# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
283852 |
2020-08-26T08:08:39 Z |
최은수(#5746) |
Ruka (COI15_ruka) |
C++17 |
|
534 ms |
14684 KB |
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
const int mx=100010;
struct seg
{
vector<int>t;
void init(int n)
{
t.resize(n*4,0);
return;
}
void upd(int n,int s,int e,int S,int E,int p)
{
if(S>E)
return upd(n,s,e,E,S,p);
if(s>E||S>e)
return;
if(S<=s&&e<=E)
{
t[n]+=p;
return;
}
int m=s+(e-s)/2;
upd(n*2,s,m,S,E,p);
upd(n*2+1,m+1,e,S,E,p);
return;
}
int query(int n,int s,int e,int x)
{
if(s==e)
return t[n];
int m=s+(e-s)/2;
int dans=0;
if(x>m)
dans=query(n*2+1,m+1,e,x);
else
dans=query(n*2,s,m,x);
return t[n]+dans;
}
}stxl,stxr,styl,styr;
int xoff,yoff;
int x[mx],y[mx];
int prvx[mx],prvy[mx];
int cox[mx],coy[mx];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
for(int i=0;i++<n;)
cin>>x[i]>>y[i],prvx[i]=x[i],prvy[i]=y[i];
vector<int>xcv,ycv;
xcv.eb(0);
ycv.eb(0);
xcv.eb(1);
ycv.eb(1);
cox[0]=coy[0]=1;
for(int i=0;i++<n;)
xcv.eb(cox[i]=cox[i-1]+x[i]),
ycv.eb(coy[i]=coy[i-1]+y[i]);
int cur=1;
int q;
cin>>q;
vector<char>qv1;
vector<pi>qv2;
for(int qi=0;qi<q;qi++)
{
char c;
cin>>c;
qv1.eb(c);
if(c=='B')
{
if(cur==1)
continue;
xcv.eb(cox[cur-1]=cox[cur]-x[cur]);
ycv.eb(coy[cur-1]=coy[cur]-y[cur]);
cur--;
}
else if(c=='F')
{
if(cur==n)
continue;
xcv.eb(cox[cur]=cox[cur-1]+x[cur]);
ycv.eb(coy[cur]=coy[cur-1]+y[cur]);
cur++;
}
else if(c=='C')
{
int nx,ny;
cin>>nx>>ny;
qv2.eb(nx,ny);
xoff+=nx-x[cur];
yoff+=ny-y[cur];
x[cur]=nx;
y[cur]=ny;
}
else
{
xcv.eb(-xoff);
ycv.eb(-yoff);
xcv.eb(cox[cur-1]+x[cur]);
ycv.eb(coy[cur-1]+y[cur]);
}
}
sort(all(xcv));
xcv.erase(unique(all(xcv)),xcv.end());
sort(all(ycv));
ycv.erase(unique(all(ycv)),ycv.end());
int xn=xcv.size(),yn=ycv.size();
stxl.init(xn),stxr.init(xn);
styl.init(yn),styr.init(yn);
auto ubx=[&](const int&x){return(int)(upper_bound(all(xcv),x)-xcv.begin());};
auto uby=[&](const int&x){return(int)(upper_bound(all(ycv),x)-ycv.begin());};
cox[0]=coy[0]=1;
for(int i=0;i++<n;)
cox[i]=cox[i-1]+(x[i]=prvx[i]),
coy[i]=coy[i-1]+(y[i]=prvy[i]);
for(int i=1;i++<n;)
stxr.upd(1,1,xn,ubx(cox[i-1]),ubx(cox[i]),1),
styr.upd(1,1,yn,uby(coy[i-1]),uby(coy[i]),1);
xoff=yoff=0;
cur=1;
for(int qi=0,qi2=0;qi<q;qi++)
{
char c=qv1[qi];
if(c=='B')
{
if(cur==1)
continue;
stxl.upd(1,1,xn,ubx(cox[cur-2]),ubx(cox[cur-1]),-1);
styl.upd(1,1,yn,uby(coy[cur-2]),uby(coy[cur-1]),-1);
cox[cur-1]=cox[cur]-x[cur];
coy[cur-1]=coy[cur]-y[cur];
cur--;
stxr.upd(1,1,xn,ubx(cox[cur]),ubx(cox[cur+1]),1);
styr.upd(1,1,yn,uby(coy[cur]),uby(coy[cur+1]),1);
}
else if(c=='F')
{
if(cur==n)
continue;
stxr.upd(1,1,xn,ubx(cox[cur]),ubx(cox[cur+1]),-1);
styr.upd(1,1,yn,uby(coy[cur]),uby(coy[cur+1]),-1);
cox[cur]=cox[cur-1]+x[cur];
coy[cur]=coy[cur-1]+y[cur];
cur++;
stxl.upd(1,1,xn,ubx(cox[cur-2]),ubx(cox[cur-1]),1);
styl.upd(1,1,yn,uby(coy[cur-2]),uby(coy[cur-1]),1);
}
else if(c=='C')
{
int nx=qv2[qi2].fi,ny=qv2[qi2].se;
qi2++;
xoff+=nx-x[cur];
yoff+=ny-y[cur];
x[cur]=nx;
y[cur]=ny;
}
else
{
int nx=cox[cur-1]+x[cur],ny=coy[cur-1]+y[cur];
int xct=((cox[cur-1]>0)==(nx>0)?0:1);
int yct=((coy[cur-1]>0)==(ny>0)?0:1);
xct+=stxl.query(1,1,xn,ubx(0))+stxr.query(1,1,xn,ubx(-xoff));
yct+=styl.query(1,1,yn,uby(0))+styr.query(1,1,yn,uby(-yoff));
cout<<(xct+yct)<<'\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
167 ms |
5604 KB |
Output is correct |
6 |
Correct |
112 ms |
4584 KB |
Output is correct |
7 |
Correct |
129 ms |
6244 KB |
Output is correct |
8 |
Correct |
132 ms |
6244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
167 ms |
5604 KB |
Output is correct |
6 |
Correct |
112 ms |
4584 KB |
Output is correct |
7 |
Correct |
129 ms |
6244 KB |
Output is correct |
8 |
Correct |
132 ms |
6244 KB |
Output is correct |
9 |
Correct |
397 ms |
12888 KB |
Output is correct |
10 |
Correct |
534 ms |
14684 KB |
Output is correct |
11 |
Correct |
421 ms |
13524 KB |
Output is correct |
12 |
Correct |
416 ms |
12880 KB |
Output is correct |