# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136360 | khsoo01 | Queue (CEOI06_queue) | C++11 | 434 ms | 20196 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |