# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
136270 | 2019-07-25T05:19:00 Z | 김현수(#3358) | Queue (CEOI06_queue) | C++14 | 397 ms | 15352 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; set<pii> 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; scanf("%d",&n); bk[inf] = inf; int CT = 1; while(n--) { int A, B; scanf("%d%d",&A,&B); if(A == B) continue; int AF = getfr(A), AB = getbk(A), BF = getfr(B); fr[AB] = AF; bk[AF] = AB; fr[A] = BF; bk[BF] = A; fr[B] = A; bk[A] = B; if(CT == B) CT = A; } for(int i=CT,j=1;i<inf;) { auto it = bk.lower_bound(i); int E = (*it).X; j += E-i; s[0].insert({E, j}); s[1].insert({j, E}); i = (*it).Y; j++; bk.erase(it); } scanf("%d",&q); while(q--) { char T[2]; int A; scanf("%s%d",T,&A); auto it = s[T[0]=='L'].lower_bound({A, 0}); printf("%d\n", (*it).Y - (*it).X + A); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Incorrect | 3 ms | 256 KB | Output isn't correct |
4 | Correct | 5 ms | 504 KB | Output is correct |
5 | Correct | 32 ms | 1276 KB | Output is correct |
6 | Correct | 44 ms | 2040 KB | Output is correct |
7 | Correct | 66 ms | 2808 KB | Output is correct |
8 | Correct | 86 ms | 4472 KB | Output is correct |
9 | Correct | 129 ms | 4720 KB | Output is correct |
10 | Correct | 135 ms | 5084 KB | Output is correct |
11 | Correct | 292 ms | 10824 KB | Output is correct |
12 | Correct | 261 ms | 8956 KB | Output is correct |
13 | Correct | 287 ms | 11000 KB | Output is correct |
14 | Incorrect | 253 ms | 8696 KB | Output isn't correct |
15 | Incorrect | 233 ms | 9080 KB | Output isn't correct |
16 | Correct | 299 ms | 11004 KB | Output is correct |
17 | Incorrect | 28 ms | 504 KB | Output isn't correct |
18 | Incorrect | 52 ms | 1084 KB | Output isn't correct |
19 | Incorrect | 87 ms | 1556 KB | Output isn't correct |
20 | Incorrect | 144 ms | 2040 KB | Output isn't correct |
21 | Incorrect | 203 ms | 9896 KB | Output isn't correct |
22 | Correct | 306 ms | 12756 KB | Output is correct |
23 | Correct | 397 ms | 15352 KB | Output is correct |
24 | Incorrect | 340 ms | 13532 KB | Output isn't correct |
25 | Incorrect | 349 ms | 12208 KB | Output isn't correct |