QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639922 | #7031. Supreme Command | RPU | WA | 194ms | 10056kb | C++14 | 3.4kb | 2024-10-13 23:55:52 | 2024-10-13 23:55:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rof(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long
#define wln putchar('\n')
template<class T1,class T2> void chkmax(T1 &x,T2 y){if(y>x)x=y;}
template<class T1,class T2> void chkmin(T1 &x,T2 y){if(y<x)x=y;}
const int N=300005;
int n,m;
int a[N],b[N],ib[N],ia[N];
char opt[10];
struct szsz
{
int v[N];
void init(){fill(v+1,v+n+1,0);}
void modify(int x,int y)
{
for(int i=x;i<=n;i+=i&-i)v[i]+=y;
}
int query(int x)
{
int res=0;
for(int i=x;i;i-=i&-i)res+=v[i];
return res;
}
}T1,T2;
void Main()
{
scanf("%d%d",&n,&m);
For(i,1,n)
{
scanf("%d%d",a+i,b+i);
ia[a[i]]=i;
ib[b[i]]=i;
}
T1.init(); T2.init();
int da=0,db=0,la=1,ra=n,lb=1,rb=n;
T1.modify(b[ia[a[1]]],1);
T2.modify(b[ia[a[n]]],1);
For(i,1,m)
{
scanf("%s",opt);
if(opt[0]=='U')
{
int x;
scanf("%d",&x);
if(la>=ra){da=max(1,da-x); continue;}
da-=x;
while(la<ra&&la+da<=0)T1.modify(b[ia[a[++la]]],1);
if(la>=ra)la=n,ra=1,da=1;
}
else if(opt[0]=='D')
{
int x;
scanf("%d",&x);
if(la>=ra){da=min(n,da+x); continue;}
da+=x;
while(la<ra&&ra+da>n)T1.modify(b[ia[a[--ra]]],1);
if(la>=ra)la=n,ra=1,da=n;
}
else if(opt[0]=='L')
{
int x;
scanf("%d",&x);
if(lb>=rb){db=max(1,db-x); continue;}
db-=x;
while(lb<rb&&lb+db<=0)lb++;
if(lb>=rb)lb=n,rb=1,db=1;
}
else if(opt[0]=='R')
{
int x;
scanf("%d",&x);
if(lb>=rb){db=min(n,db+x); continue;}
db+=x;
while(lb<rb&&rb+db>n)rb--;
if(lb>=rb)lb=n,rb=1,db=n;
}
else if(opt[0]=='?')
{
int x;
scanf("%d",&x);
int ax=0,bx=0;
if(la>=ra)ax=da;
else if(a[x]<=la)ax=la+da;
else if(a[x]>=ra)ax=ra+da;
else ax=a[x]+da;
if(lb>=rb)bx=db;
else if(b[x]<=lb)bx=lb+db;
else if(b[x]>=rb)bx=rb+db;
else bx=b[x]+db;
printf("%d %d\n",ax,bx);
}
else
{
ll ans=0;
if(la>=ra)
{
if(lb>=rb)ans=1ll*n*(n-1)/2;
else ans=1ll*lb*(lb-1)/2+1ll*(n-rb+1)*(n-rb)/2;
}
else
{
if(lb>=rb)ans=1ll*la*(la-1)/2+1ll*(n-ra+1)*(n-ra)/2;
else
{
int cnt1=T1.query(lb),cnt2=la-T1.query(rb-1),cnt3=T2.query(lb),cnt4=n-ra+1-T2.query(rb-1);
ans+=1ll*cnt1*(cnt1-1)/2;
ans+=1ll*cnt2*(cnt2-1)/2;
ans+=1ll*cnt3*(cnt3-1)/2;
ans+=1ll*cnt4*(cnt4-1)/2;
}
}
printf("%lld\n",ans);
}
// printf("a:[%d|%d|%d]\n",la,da,ra);
// printf("b:[%d|%d|%d]\n",lb,db,rb);
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)Main();
}
/*
1
4 9
3 4
2 1
4 2
1 3
L 2
? 1
? 2
R 1
? 1
? 3
!
U 3
!
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10056kb
input:
1 4 9 3 4 2 1 4 2 1 3 L 2 ? 1 ? 2 R 1 ? 1 ? 3 ! U 3 !
output:
3 2 2 1 3 3 4 2 0 3
result:
ok 6 lines
Test #2:
score: -100
Wrong Answer
time: 194ms
memory: 7884kb
input:
500 2000 2000 492 502 1394 1025 980 1484 1135 599 760 242 575 1393 833 341 1364 453 1692 1515 1303 7 1429 1519 887 86 205 1874 1483 1797 649 1677 1717 298 416 1673 1696 896 1998 1154 638 1725 667 96 1467 1788 1438 759 285 1987 1985 736 95 140 596 1076 1089 238 1212 247 1287 1705 891 1237 941 622 930...
output:
170 1229 0 1610 1081 0 616 1509 0 1419 1109 0 1584 1103 0 459 1193 0 1891 1713 0 806 187 0 115 81 0 1035 378 0 1673 276 0 529 1976 0 1380 639 0 397 1375 0 144 806 0 579 495 0 1817 1065 0 369 828 0 1226 790 0 740 1967 0 37 311 0 1466 391 0 160 898 0 97 1023 0 1086 754 0 670 1932 0 831 909 0 1964 255 ...
result:
wrong answer 33968th lines differ - expected: '0', found: '1'