답안 #136283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136283 2019-07-25T05:36:49 Z 김현수(#3358) Queue (CEOI06_queue) C++14
100 / 100
408 ms 20192 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

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);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 68 ms 3448 KB Output is correct
8 Correct 95 ms 5684 KB Output is correct
9 Correct 99 ms 6008 KB Output is correct
10 Correct 116 ms 6716 KB Output is correct
11 Correct 297 ms 14632 KB Output is correct
12 Correct 255 ms 12024 KB Output is correct
13 Correct 318 ms 14456 KB Output is correct
14 Correct 294 ms 14456 KB Output is correct
15 Correct 308 ms 14624 KB Output is correct
16 Correct 299 ms 14456 KB Output is correct
17 Correct 29 ms 504 KB Output is correct
18 Correct 57 ms 1360 KB Output is correct
19 Correct 93 ms 1912 KB Output is correct
20 Correct 151 ms 2808 KB Output is correct
21 Correct 234 ms 13916 KB Output is correct
22 Correct 301 ms 16652 KB Output is correct
23 Correct 403 ms 20192 KB Output is correct
24 Correct 408 ms 20088 KB Output is correct
25 Correct 342 ms 15840 KB Output is correct