# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
348428 |
2021-01-15T02:11:07 Z |
duality |
Ruka (COI15_ruka) |
C++11 |
|
109 ms |
5356 KB |
#define DEBUG 1
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
int diff(int a,int b) {
return (a > 0) != (b > 0);
}
int x[100000],y[100000];
int a[100001],b[100001];
int bita[10000000],bitb[10000000];
int update(int i,int num,int *bit) {
for (i += 5000000; i < 10000000; i += i & (-i)) bit[i] += num;
return 0;
}
int query(int i,int *bit) {
int sum = 0;
for (i += 5000000; i > 0; i -= i & (-i)) sum += bit[i];
return sum;
}
int main() {
int i;
int N,M;
char c;
int nx,ny;
int u = 0,ans = 0,adda = 0,addb = 0;
scanf("%d",&N);
a[0] = b[0] = 1;
for (i = 0; i < N; i++) scanf("%d %d",&x[i],&y[i]),a[i+1] = a[i]+x[i],b[i+1] = b[i]+y[i];
ans += diff(a[0],a[1])+diff(b[0],b[1]);
for (i = 1; i < N; i++) {
update(min(a[i],a[i+1]),1,bita),update(max(a[i],a[i+1])+1,-1,bita);
update(min(b[i],b[i+1]),1,bitb),update(max(b[i],b[i+1])+1,-1,bitb);
}
scanf("%d",&M);
for (i = 0; i < M; i++) {
scanf(" %c",&c);
if (c == 'B') {
if (u == 0) continue;
ans -= diff(a[u],a[u+1]+adda)+diff(b[u],b[u+1]+addb);
a[u] -= adda,b[u] -= addb;
update(min(a[u],a[u+1]),1,bita),update(max(a[u],a[u+1])+1,-1,bita);
update(min(b[u],b[u+1]),1,bitb),update(max(b[u],b[u+1])+1,-1,bitb);
u--;
}
else if (c == 'F') {
if (u == N-1) continue;
u++;
update(min(a[u],a[u+1]),-1,bita),update(max(a[u],a[u+1])+1,1,bita);
update(min(b[u],b[u+1]),-1,bitb),update(max(b[u],b[u+1])+1,1,bitb);
a[u] += adda,b[u] += addb;
ans += diff(a[u],a[u+1]+adda)+diff(b[u],b[u+1]+addb);
}
else if (c == 'C') {
scanf("%d %d",&nx,&ny);
ans -= diff(a[u],a[u+1]+adda)+diff(b[u],b[u+1]+addb);
adda += nx-x[u],addb += ny-y[u];
ans += diff(a[u],a[u+1]+adda)+diff(b[u],b[u+1]+addb);
x[u] = nx,y[u] = ny;
}
else printf("%d\n",ans+query(-adda,bita)+query(-addb,bitb));
/*printArr(a,N+1);
printArr(b,N+1);
printVar(adda);
printVar(addb);
printVar(ans);*/
}
return 0;
}
Compilation message
ruka.cpp: In function 'int main()':
ruka.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
79 | scanf("%d",&N);
| ~~~~~^~~~~~~~~
ruka.cpp:81:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
81 | for (i = 0; i < N; i++) scanf("%d %d",&x[i],&y[i]),a[i+1] = a[i]+x[i],b[i+1] = b[i]+y[i];
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
ruka.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
87 | scanf("%d",&M);
| ~~~~~^~~~~~~~~
ruka.cpp:89:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
89 | scanf(" %c",&c);
| ~~~~~^~~~~~~~~~
ruka.cpp:107:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
107 | scanf("%d %d",&nx,&ny);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
42 ms |
2540 KB |
Output is correct |
6 |
Correct |
35 ms |
2048 KB |
Output is correct |
7 |
Correct |
44 ms |
2424 KB |
Output is correct |
8 |
Correct |
46 ms |
2540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
42 ms |
2540 KB |
Output is correct |
6 |
Correct |
35 ms |
2048 KB |
Output is correct |
7 |
Correct |
44 ms |
2424 KB |
Output is correct |
8 |
Correct |
46 ms |
2540 KB |
Output is correct |
9 |
Correct |
97 ms |
4332 KB |
Output is correct |
10 |
Correct |
109 ms |
5356 KB |
Output is correct |
11 |
Correct |
97 ms |
4716 KB |
Output is correct |
12 |
Correct |
100 ms |
4844 KB |
Output is correct |