const unsigned int INPUT_BUF_SIZE = 20 << 20; const unsigned int OUTPUT_BUF_SIZE = 3 << 20; #include #include char input_buf[INPUT_BUF_SIZE]; struct input_buf_init{ input_buf_init(){ input_buf[fread(input_buf, 1, INPUT_BUF_SIZE-1, stdin)] = '\0'; } } input_buf_init_instance; struct input_buf_iterator{ private: unsigned int p = 0; public: static bool is_whitespace(char ch){ switch(ch){ case ' ': case '\n': case '\r': case '\t': return true; } return false; } void skip_whitespace(){ while(is_whitespace(input_buf[p])) p++; } unsigned int next_uint(){ skip_whitespace(); unsigned int buf = 0; while(true){ char tmp = input_buf[p]; if('9' < tmp || tmp < '0') break; buf = buf * 10 + (tmp - '0'); p++; } return buf; } int next_int(){ skip_whitespace(); if(input_buf[p] == '-'){ p++; return (int)(-next_uint()); } return (int)next_uint(); } unsigned long long next_ulong(){ skip_whitespace(); unsigned long long buf = 0; while(true){ char tmp = input_buf[p]; if('9' < tmp || tmp < '0') break; buf = buf * 10 + (tmp - '0'); p++; } return buf; } long long next_long(){ skip_whitespace(); if(input_buf[p] == '-'){ p++; return (long long)(-next_ulong()); } return (long long)next_ulong(); } char next_char(){ skip_whitespace(); return input_buf[p++]; } std::string next_token(){ skip_whitespace(); std::string buf; while(true){ char ch = input_buf[p]; if(is_whitespace(ch)) break; buf.push_back(ch); p++; } return buf; } }; char output_buf[OUTPUT_BUF_SIZE] = {}; struct fastoutput_table{ char dig3lz[1000][4]; char dig3nlz[1000][4]; fastoutput_table(){ for(unsigned int d=0; d<1000; d++){ unsigned int x = d; unsigned int i = 0; dig3lz[d][i++] = ('0' + x / 100 % 10); dig3lz[d][i++] = ('0' + x / 10 % 10); dig3lz[d][i++] = ('0' + x / 1 % 10); dig3lz[d][i++] = '\0'; } for(unsigned int d=0; d<1000; d++){ unsigned int x = d; unsigned int i = 0; if(x >= 100) dig3nlz[d][i++] = ('0' + x / 100 % 10); if(x >= 10) dig3nlz[d][i++] = ('0' + x / 10 % 10); if(x >= 1) dig3nlz[d][i++] = ('0' + x / 1 % 10); dig3nlz[d][i++] = '\0'; } } } fastoutput_table_inst; struct output_buf_iterator{ unsigned int p = 0; void next_char(char c){ output_buf[p++] = c; } void next_eoln(){ next_char('\n'); } void next_cstr(char* s){ int i = 0; while(s[i]) next_char(s[i++]); } void next_dig9(unsigned int x){ unsigned int y; y = x / 1'000'000; x -= y * 1'000'000; next_cstr(fastoutput_table_inst.dig3lz [y]); y = x / 1'000; x -= y * 1'000; next_cstr(fastoutput_table_inst.dig3lz [y]); y = x; next_cstr(fastoutput_table_inst.dig3lz [y]); } void next_uint(unsigned int x){ unsigned int y = 0; if(x >= 1'000'000'000){ y = x / 1'000'000'000; x -= y * 1'000'000'000; next_cstr(fastoutput_table_inst.dig3nlz[y]); next_dig9(x); } else if(x >= 1'000'000){ y = x / 1'000'000; x -= y * 1'000'000; next_cstr(fastoutput_table_inst.dig3nlz[y]); y = x / 1'000; x -= y * 1'000; next_cstr(fastoutput_table_inst.dig3lz [y]); next_cstr(fastoutput_table_inst.dig3lz [x]); } else if(x >= 1'000){ y = x / 1'000; x -= y * 1'000; next_cstr(fastoutput_table_inst.dig3nlz[y]); next_cstr(fastoutput_table_inst.dig3lz [x]); } else if(x >= 1){ next_cstr(fastoutput_table_inst.dig3nlz[x]); } else{ next_char('0'); } } void next_ulong(unsigned long long x){ unsigned int y = 0; if(x >= 1'000'000'000'000'000'000){ y = x / 1'000'000'000'000'000'000; x -= (unsigned long long)y * 1'000'000'000'000'000'000; next_uint(y); y = x / 1'000'000'000; x -= (unsigned long long)y * 1'000'000'000; next_dig9(y); next_dig9(x); } else if(x >= 1'000'000'000){ y = x / 1'000'000'000; x -= (unsigned long long)y * 1'000'000'000; next_uint(y); next_dig9(x); } else{ next_uint(x); } } void write_to_file(){ fwrite(output_buf, p, 1, stdout); } }; #include #include #include using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) const u32 MOD = 998244353; struct F{ u32 a=1, b=0; u32 operator()(u32 x){ return ((u64)a*x + b) % MOD; } F operator+(F r){ return { (u32)(((u64)a*r.a) % MOD), (u32)(((u64)b*r.a+r.b) % MOD) }; } }; #include struct Segtree{ int N, logN; vector> A; Segtree(vector a){ int n = a.size(); N = 1; logN = 0; while(N < n){ N *= 2; logN++; } A.resize(logN+1); A[0] = a; A[0].resize(N); rep(d,logN){ auto tmp = A[d]; rep(i,N) if((i&(1< A(N); rep(i,N){ A[i].a = iitr.next_uint(); A[i].b = iitr.next_uint(); } Segtree rq(A); rep(i,Q){ int l = iitr.next_uint(); int r = iitr.next_uint(); int p = iitr.next_uint(); u32 x = iitr.next_uint(); u32 ans = rq.prod(l,r,p)(x); oitr.next_uint(ans); oitr.next_eoln(); } oitr.write_to_file(); return 0; }