結果
問題 | No.1891 Static Xor Range Composite Query |
ユーザー | 👑 Nachia |
提出日時 | 2022-04-04 18:43:55 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 179 ms / 5,000 ms |
コード長 | 6,859 bytes |
コンパイル時間 | 841 ms |
コンパイル使用メモリ | 90,208 KB |
実行使用メモリ | 60,612 KB |
最終ジャッジ日時 | 2024-11-25 10:57:26 |
合計ジャッジ時間 | 5,341 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 3 ms
6,820 KB |
testcase_12 | AC | 2 ms
6,816 KB |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | AC | 2 ms
6,816 KB |
testcase_15 | AC | 2 ms
6,816 KB |
testcase_16 | AC | 2 ms
6,820 KB |
testcase_17 | AC | 2 ms
6,816 KB |
testcase_18 | AC | 2 ms
6,816 KB |
testcase_19 | AC | 3 ms
6,816 KB |
testcase_20 | AC | 2 ms
6,820 KB |
testcase_21 | AC | 170 ms
60,612 KB |
testcase_22 | AC | 179 ms
58,564 KB |
testcase_23 | AC | 173 ms
60,612 KB |
testcase_24 | AC | 176 ms
59,324 KB |
testcase_25 | AC | 170 ms
58,568 KB |
testcase_26 | AC | 179 ms
59,508 KB |
testcase_27 | AC | 178 ms
58,740 KB |
testcase_28 | AC | 178 ms
58,688 KB |
testcase_29 | AC | 169 ms
58,564 KB |
testcase_30 | AC | 174 ms
59,308 KB |
ソースコード
const unsigned int INPUT_BUF_SIZE = 20 << 20; const unsigned int OUTPUT_BUF_SIZE = 3 << 20; #include <cstdio> #include <string> 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 <iostream> #include <vector> #include <algorithm> 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 <tuple> struct Segtree{ int N, logN; vector<vector<F>> A; Segtree(vector<F> 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<<d)) == 0){ tie(tmp[i], tmp[i|(1<<d)]) = make_pair( tmp[i] + tmp[i|(1<<d)], tmp[i|(1<<d)] + tmp[i] ); } A[d+1] = move(tmp); } } F prod(int l, int r, int x){ F ql, qr; int d = 0; while(l < r){ if(l & 1){ ql = ql + A[d][(l<<d)^x]; l++; } if(r & 1){ r--; qr = A[d][(r<<d)^x] + qr; } l /= 2; r /= 2; d++; } return ql + qr; } }; int main(){ input_buf_iterator iitr; output_buf_iterator oitr; int N = iitr.next_uint(); int Q = iitr.next_uint(); vector<F> 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; }