#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 7;
int n, m;
array<int, 2> p[MAXN];
array<int, 3> queries[MAXN];
int get_answer(){
int ret = 0;
int x = 1, y = 1;
for(int i = 0; i < n; ++i){
int newx = x + p[i][0], newy = y + p[i][1];
ret += ((newx > 0) ^ (x > 0));
ret += ((newy > 0) ^ (y > 0));
x = newx, y = newy;
}
return ret;
}
void solve(){
int curr_line = 0;
for(int i = 0; i < m; ++i){
int type = queries[i][0];
if(type == 'Q'){
cout << get_answer() << "\n";
continue;
}
if(type == 'B'){
if(curr_line != 0)
--curr_line;
continue;
}
if(type == 'F'){
if(curr_line != n - 1)
++curr_line;
continue;
}
//type == 'C'
p[curr_line] = {queries[i][1], queries[i][2]};
}
}
void read(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n; ++i){
cin >> p[i][0] >> p[i][1];
}
cin >> m;
for(int i = 0; i < m; ++i){
char type;
cin >> type;
queries[i][0] = type;
if(type == 'C'){
cin >> queries[i][1] >> queries[i][2];
}
}
}
int main(){
read();
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
248 KB |
Output is correct |
3 |
Correct |
6 ms |
504 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
248 KB |
Output is correct |
3 |
Correct |
6 ms |
504 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Execution timed out |
2047 ms |
3376 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
248 KB |
Output is correct |
3 |
Correct |
6 ms |
504 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Execution timed out |
2047 ms |
3376 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |