結果
問題 | No.1471 Sort Queries |
ユーザー | LayCurse |
提出日時 | 2021-04-09 21:24:10 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 7,060 bytes |
コンパイル時間 | 2,744 ms |
コンパイル使用メモリ | 213,808 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 04:00:18 |
合計ジャッジ時間 | 4,273 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | AC | 4 ms
5,376 KB |
testcase_15 | AC | 3 ms
5,376 KB |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | AC | 3 ms
5,376 KB |
testcase_18 | AC | 3 ms
5,376 KB |
testcase_19 | AC | 3 ms
5,376 KB |
testcase_20 | AC | 4 ms
5,376 KB |
testcase_21 | AC | 3 ms
5,376 KB |
testcase_22 | AC | 3 ms
5,376 KB |
testcase_23 | AC | 4 ms
5,376 KB |
testcase_24 | AC | 4 ms
5,376 KB |
testcase_25 | AC | 5 ms
5,376 KB |
testcase_26 | AC | 4 ms
5,376 KB |
testcase_27 | AC | 4 ms
5,376 KB |
testcase_28 | AC | 4 ms
5,376 KB |
testcase_29 | AC | 4 ms
5,376 KB |
testcase_30 | AC | 4 ms
5,376 KB |
testcase_31 | AC | 4 ms
5,376 KB |
testcase_32 | AC | 4 ms
5,376 KB |
testcase_33 | AC | 5 ms
5,376 KB |
testcase_34 | AC | 5 ms
5,376 KB |
testcase_35 | AC | 5 ms
5,376 KB |
testcase_36 | AC | 4 ms
5,376 KB |
testcase_37 | AC | 5 ms
5,376 KB |
testcase_38 | AC | 3 ms
5,376 KB |
testcase_39 | AC | 5 ms
5,376 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; void*wmem; char memarr[96000000]; template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){ walloc1d(arr, x2-x1, mem); (*arr) -= x1; } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void rd(char &c){ int i; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c = i; } inline int rd(char c[]){ int i; int sz = 0; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c[sz++] = i; for(;;){ i = my_getchar_unlocked(); if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){ break; } c[sz++] = i; } c[sz]='\0'; return sz; } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(unsigned x){ int s=0; char f[10]; while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(unsigned long long x){ int s=0; char f[21]; while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } while(s--){ my_putchar_unlocked(f[s]+'0'); } } int WRITER_DOUBLE_DIGIT = 15; inline int writerDigit_double(){ return WRITER_DOUBLE_DIGIT; } inline void writerDigit_double(int d){ WRITER_DOUBLE_DIGIT = d; } inline void wt_L(double x){ const int d = WRITER_DOUBLE_DIGIT; int k; int r; double v; if(x!=x || (x==x+1 && x==2*x)){ my_putchar_unlocked('E'); my_putchar_unlocked('r'); my_putchar_unlocked('r'); return; } if(x < 0){ my_putchar_unlocked('-'); x = -x; } x += 0.5 * pow(0.1, d); r = 0; v = 1; while(x >= 10*v){ v *= 10; r++; } while(r >= 0){ r--; k = floor(x / v); if(k >= 10){ k = 9; } if(k <= -1){ k = 0; } x -= k * v; v *= 0.1; my_putchar_unlocked(k + '0'); } if(d > 0){ my_putchar_unlocked('.'); v = 1; for(r=(0);r<(d);r++){ v *= 0.1; k = floor(x / v); if(k >= 10){ k = 9; } if(k <= -1){ k = 0; } x -= k * v; my_putchar_unlocked(k + '0'); } } } inline void wt_L(const char c[]){ int i=0; for(i=0;c[i]!='\0';i++){ my_putchar_unlocked(c[i]); } } inline void wt_L(string &x){ int i=0; for(i=0;x[i]!='\0';i++){ my_putchar_unlocked(x[i]); } } template<class T> struct Arr1d{ int n; int mem; T*d; T& operator[](int a){ return d[a]; } void sort(){ reset(); std::sort(d, d+n); } int set_cumulative_sum; int cumulative_sum_mem; T*cumulative_sum; void setSum(void){ int i; set_cumulative_sum = 1; if(cumulative_sum_mem < n+1){ delete[] cumulative_sum; cumulative_sum = new T[n+1]; cumulative_sum_mem = n+1; } cumulative_sum[0] = 0; for(i=(0);i<(n);i++){ cumulative_sum[i+1] = cumulative_sum[i] + d[i]; } } T getSum(int i, int j){ if(set_cumulative_sum==0){ setSum(); } return cumulative_sum[j+1] - cumulative_sum[i]; } void reset(){ set_cumulative_sum = 0; } void constructor(){ n = mem = 0; d = NULL; set_cumulative_sum = 0; cumulative_sum_mem = 0; cumulative_sum = NULL; } void destructor(){ delete[] d; d = NULL; mem = n = 0; set_cumulative_sum = 0; cumulative_sum_mem = 0; delete[] cumulative_sum; cumulative_sum = NULL; } void constructor(int nn){ constructor(); malloc(nn); } void memory_expand(int nn){ if(mem < nn){ delete[] d; d = new T[nn]; mem = nn; } } void malloc(int nn){ reset(); memory_expand(nn); n = nn; } void setN(int nn){ reset(); memory_expand(nn); n = nn; } void set(vector<T> &a){ int i; int nn = a.size(); setN(nn); for(i=(0);i<(nn);i++){ d[i] = a[i]; } } void set(int nn, T a[]){ int i; setN(nn); for(i=(0);i<(nn);i++){ d[i] = a[i]; } } void free(){ destructor(); } Arr1d(){ constructor(); } Arr1d(int nn){ constructor(nn); } ~Arr1d(){ destructor(); } } ; int N; int Q; int L; int R; int X; char S[100000]; Arr1d<int> h[26]; int main(){ int KrdatlYV, i; wmem = memarr; rd(N); rd(Q); rd(S); for(i=(0);i<(N);i++){ S[i] -= 'a'; } for(i=(0);i<(26);i++){ h[i].setN(N); } for(i=(0);i<(26);i++){ int j; for(j=(0);j<(N);j++){ h[i][j] = 0; } } for(i=(0);i<(N);i++){ h[S[i]][i] = 1; } for(KrdatlYV=(0);KrdatlYV<(Q);KrdatlYV++){ rd(L);L += (-1); rd(R);R += (-1); rd(X);X += (-1); for(i=(0);i<(26);i++){ X -= h[i].getSum(L,R); if(X < 0){ wt_L((char)('a'+i)); wt_L('\n'); break; } } } return 0; } // cLay version 20210405-1 // --- original code --- // int N, Q, L, R, X; char S[1d5]; // Arr1d<int> h[26]; // { // rd(N,Q,S); // rep(i,N) S[i] -= 'a'; // rep(i,26) h[i].setN(N); // rep(i,26) rep(j,N) h[i][j] = 0; // rep(i,N) h[S[i]][i] = 1; // rep(Q){ // rd(L--, R--, X--); // rep(i,26){ // X -= h[i].getSum(L,R); // if(X < 0) Wt((char)('a'+i)), break; // } // } // }