Submission #136360

#TimeUsernameProblemLanguageResultExecution timeMemory
136360khsoo01Queue (CEOI06_queue)C++11
100 / 100
434 ms20196 KiB
#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)

queue.cpp: In function 'int main()':
queue.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
queue.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&A,&B);
   ~~~~~^~~~~~~~~~~~~~
queue.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&q);
  ~~~~~^~~~~~~~~
queue.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s%d",T,&A);
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...