| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 658357 | Dec0Dedd | Queue (CEOI06_queue) | C++14 | 245 ms | 21556 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
map<int, int> bf, af, s[2];
map<int, pii> pos;
const int N = 5e4+1;
const int INF = 1e9+7;
int prv(int x) {
if (bf.find(x) != bf.end()) return bf[x];
return x+1;
}
int nxt(int x) {
if (af.find(x) != af.end()) return af[x];
return x-1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n, x=1; cin>>n;
for (int i=1; i<=n; ++i) {
int a, b; cin>>a>>b;
int afr=nxt(a), abk=prv(a), bfr=nxt(b);
if (a == b || abk == b) continue;
af[abk]=afr, bf[afr]=abk;
af[a]=bfr, bf[bfr]=a;
af[b]=a, bf[a]=b;
if (x == a) x=abk;
if (x == b) x=a;
} bf[INF]=INF;
for (int i=x, j=1; i<INF;) {
auto it=bf.lower_bound(i);
int e=(*it).first; j+=e-i;
s[0][e]=j, s[1][j]=e;
i=(*it).second; ++j;
}
int q; cin>>q;
while (q--) {
char c; cin>>c;
int a; cin>>a;
auto p=s[c == 'L'].lower_bound(a);
cout<<(p->second-p->first+a)<<"\n";
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
