# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1010824 |
2024-06-29T12:03:27 Z |
vjudge1 |
Queue (CEOI06_queue) |
C++17 |
|
1000 ms |
16980 KB |
#include<bits/stdc++.h>
using namespace std;
#ifdef ONPC
#include"debug.h"
#else
#define debug(...) 42
#endif
#define endl '\n'
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
//#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 15;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
map<int, int> prv, nxt;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
int pa = (prv.count(a) ? prv[a] : a - 1);
int na = (nxt.count(a) ? nxt[a] : a + 1);
nxt[pa] = na;
prv[na] = pa;
int pb = (prv.count(b) ? prv[b] : b - 1);
nxt[pb] = a;
prv[a] = pb;
nxt[a] = b;
prv[b] = a;
}
int q;
cin >> q;
vector<array<int, 3>> queries(q);
for (int i = 0; i < q; i++){
char t; cin >> t;
int x, y;
x = t == 'P';
cin >> y;
if (nxt.count(y) == 0){
nxt[y] = y + 1;
prv[y + 1] = y;
}
if (prv.count(y) == 0){
prv[y] = y - 1;
nxt[y - 1] = y;
}
queries[i] = {y, x, i};
}
sort(all(queries));
vector<int> ans(q);
int cur = (nxt.count(0) ? nxt[0] : 1);
int pos = 1;
for (int i = 0; i < q; i++){
while (cur != queries[i][0]){
if (nxt.count(cur)){
cur = nxt[cur];
pos++;
} else {
int up = nxt.upper_bound(cur)->first;
pos += up - cur;
cur = up;
}
}
debug(queries[i], cur, pos);
ans[queries[i][2]] = pos;
}
for (int i = 0; i < q; i++){
cout << ans[i] << endl;
}
}
Compilation message
queue.cpp: In function 'int main()':
queue.cpp:6:20: warning: statement has no effect [-Wunused-value]
6 | #define debug(...) 42
| ^~
queue.cpp:78:3: note: in expansion of macro 'debug'
78 | debug(queries[i], cur, pos);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Partially correct |
2 |
Execution timed out |
1075 ms |
348 KB |
Time limit exceeded |
3 |
Execution timed out |
1078 ms |
348 KB |
Time limit exceeded |
4 |
Partially correct |
82 ms |
604 KB |
Partially correct |
5 |
Execution timed out |
1048 ms |
10028 KB |
Time limit exceeded |
6 |
Execution timed out |
1051 ms |
10556 KB |
Time limit exceeded |
7 |
Execution timed out |
1067 ms |
4180 KB |
Time limit exceeded |
8 |
Execution timed out |
1066 ms |
12008 KB |
Time limit exceeded |
9 |
Execution timed out |
1020 ms |
10688 KB |
Time limit exceeded |
10 |
Execution timed out |
1068 ms |
10840 KB |
Time limit exceeded |
11 |
Execution timed out |
1057 ms |
7508 KB |
Time limit exceeded |
12 |
Execution timed out |
1069 ms |
6228 KB |
Time limit exceeded |
13 |
Execution timed out |
1041 ms |
7812 KB |
Time limit exceeded |
14 |
Execution timed out |
1083 ms |
8532 KB |
Time limit exceeded |
15 |
Execution timed out |
1066 ms |
8788 KB |
Time limit exceeded |
16 |
Execution timed out |
1026 ms |
8120 KB |
Time limit exceeded |
17 |
Partially correct |
233 ms |
2896 KB |
Partially correct |
18 |
Execution timed out |
1004 ms |
4404 KB |
Time limit exceeded |
19 |
Execution timed out |
1027 ms |
2896 KB |
Time limit exceeded |
20 |
Execution timed out |
1043 ms |
7760 KB |
Time limit exceeded |
21 |
Execution timed out |
1080 ms |
12628 KB |
Time limit exceeded |
22 |
Execution timed out |
1058 ms |
13836 KB |
Time limit exceeded |
23 |
Execution timed out |
1047 ms |
16464 KB |
Time limit exceeded |
24 |
Execution timed out |
1056 ms |
16980 KB |
Time limit exceeded |
25 |
Execution timed out |
1059 ms |
10248 KB |
Time limit exceeded |