# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136360 | 2019-07-25T07:50:48 Z | khsoo01 | Queue (CEOI06_queue) | C++11 | 434 ms | 20196 KB |
#include<bits/stdc++.h> #define X first #define Y second using namespace std; typedef pair<int,int> pii; const int N = 50005, inf = 1e9+7; map<int, int> fr, bk, s[2]; int getfr (int I) { if(fr.find(I) == fr.end()) return I-1; return fr[I]; } int getbk (int I) { if(bk.find(I) == bk.end()) return I+1; return bk[I]; } int main() { int n, q, CT = 1; scanf("%d",&n); while(n--) { int A, B; scanf("%d%d",&A,&B); int AF = getfr(A), AB = getbk(A), BF = getfr(B); if(A == B || AB == B) continue; fr[AB] = AF; bk[AF] = AB; fr[A] = BF; bk[BF] = A; fr[B] = A; bk[A] = B; if(CT == A) CT = AB; if(CT == B) CT = A; } bk[inf] = inf; for(int i=CT,j=1;i<inf;) { auto it = bk.lower_bound(i); int E = (*it).X; j += E-i; s[0][E] = j; s[1][j] = E; i = (*it).Y; j++; } scanf("%d",&q); while(q--) { char T[2]; int A; scanf("%s%d",T,&A); auto it = s[T[0]=='L'].lower_bound(A); printf("%d\n", (*it).Y - (*it).X + A); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 252 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 504 KB | Output is correct |
5 | Correct | 31 ms | 1400 KB | Output is correct |
6 | Correct | 43 ms | 2424 KB | Output is correct |
7 | Correct | 64 ms | 3448 KB | Output is correct |
8 | Correct | 88 ms | 5628 KB | Output is correct |
9 | Correct | 93 ms | 6008 KB | Output is correct |
10 | Correct | 113 ms | 6628 KB | Output is correct |
11 | Correct | 323 ms | 14584 KB | Output is correct |
12 | Correct | 264 ms | 11976 KB | Output is correct |
13 | Correct | 287 ms | 14452 KB | Output is correct |
14 | Correct | 285 ms | 14584 KB | Output is correct |
15 | Correct | 286 ms | 14584 KB | Output is correct |
16 | Correct | 284 ms | 14456 KB | Output is correct |
17 | Correct | 30 ms | 504 KB | Output is correct |
18 | Correct | 56 ms | 1248 KB | Output is correct |
19 | Correct | 89 ms | 1792 KB | Output is correct |
20 | Correct | 154 ms | 2708 KB | Output is correct |
21 | Correct | 236 ms | 13996 KB | Output is correct |
22 | Correct | 300 ms | 16532 KB | Output is correct |
23 | Correct | 384 ms | 20088 KB | Output is correct |
24 | Correct | 434 ms | 20196 KB | Output is correct |
25 | Correct | 344 ms | 15948 KB | Output is correct |