QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#547652 | #7072. Photograph | ucup-team3474 | WA | 1ms | 10036kb | C++20 | 3.1kb | 2024-09-05 01:06:04 | 2024-09-05 01:06:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1919810,inf=0x3f3f3f3f;
typedef long long ll;
typedef pair<ll,ll> PII;
#define int long long
ll n,m,k;
ll a[N],b[N];
char s[N];
ll c[N];
int lst[N],ne[N];
typedef struct{
int l,r;
int mx,mn;
int tag1,tag2;
}Node;
Node tr[N];
// void pushup(int u){
// tr[u].mx=max(tr[u<<1].mx,tr[u<<1|1].mx);
// }
void pushdown(int u){
if(tr[u].tag1!=0){
if(tr[u<<1].l==tr[u<<1].r) tr[u<<1].mx=max(tr[u<<1].mx,tr[u].tag1);
if(tr[u<<1|1].l==tr[u<<1|1].r) tr[u<<1|1].mx=max(tr[u<<1|1].mx,tr[u].tag1);
tr[u<<1].tag1=max(tr[u<<1].tag1,tr[u].tag1);
tr[u<<1|1].tag1=max(tr[u<<1|1].tag1,tr[u].tag1);
tr[u].tag1=0;
}
if(tr[u].tag2!=inf){
if(tr[u<<1].l==tr[u<<1].r) tr[u<<1].mn=min(tr[u<<1].mn,tr[u].tag2);
if(tr[u<<1|1].l==tr[u<<1|1].r) tr[u<<1|1].mn=min(tr[u<<1|1].mn,tr[u].tag2);
tr[u<<1].tag2=min(tr[u<<1].tag2,tr[u].tag2);
tr[u<<1|1].tag2=min(tr[u<<1|1].tag2,tr[u].tag2);
tr[u].tag2=inf;
}
}
void build(int u,int l,int r){
tr[u]={l,r,0,inf,0,inf};
if(l==r){
// tr[u].lst=
return;
}else{
int mid=l+r>>1;
build(u<<1,l,mid);
build(u<<1|1,mid+1,r);
// pushup(u);
}
}
void modify(int u,int l,int r,int c,int type){
// cout<<u<<" "<<tr[u].l<<" "<<tr[u].r<<" "<<l<<" "<<r<<endl;
if(l>r) return;
pushdown(u);
if(tr[u].l>=l&&tr[u].r<=r){
if(type==1){
if(tr[u].l==tr[u].r) tr[u].mx=max(tr[u].mx,c);
tr[u].tag1=max(tr[u].tag1,c);
}
if(type==2){
if(tr[u].l==tr[u].r) tr[u].mn=min(tr[u].mn,c);
tr[u].tag2=min(tr[u].tag2,c);
}
}else{
pushdown(u);
int mid=tr[u].l+tr[u].r>>1;
if(l<=mid) modify(u<<1,l,r,c,type);
if(r>mid) modify(u<<1|1,l,r,c,type);
// pushup(u);
}
}
Node query(int u,int l){
pushdown(u);
if(tr[u].l==tr[u].r){
return tr[u];
}else{
pushdown(u);
int mid=tr[u].l+tr[u].r>>1;
if(l<=mid) return query(u<<1,l);
else return query(u<<1|1,l);
}
}
void __(){
scanf("%lld%lld",&n,&m);
for(int i=0;i<n;i++) scanf("%lld",&b[i]);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
for(int i=0;i<n;i++){
a[i+n]=a[i];
b[i+n]=b[i];
}
for(int i=0;i<n;i++) c[a[i]]=b[i];
int id=0;
do{
build(1,1,n);
ll now=0;
ll ans=0;
for(int i=id,j=1;j<=n;j++,i++){
// cout<<a[i]<<" ";
Node nd=query(1,a[i]);
// cout<<114514<<endl;
int lst=nd.mx,ne=nd.mn;
// cout<<lst<<" "<<ne<<endl;
ll res=0;
if(lst!=0&&ne!=inf){
res-=(c[lst]-c[ne])*(c[lst]-c[ne]);
}
// cout<<res<<" ";
if(lst!=0){
res+=(c[a[i]]-c[lst])*(c[a[i]]-c[lst]);
}
// cout<<res<<" ";
if(ne!=inf){
res+=(c[a[i]]-c[ne])*(c[a[i]]-c[ne]);
}
// cout<<res<<" ";
// cout<<a[i]<<" ";
// cout<<lst<<" "<<ne<<" "<<res<<endl;
modify(1,a[i]+1,n,a[i],1);
modify(1,1,a[i]-1,a[i],2);
now+=res;
ans+=now;
// cout<<ans<<endl;
}
// cout<<endl;
printf("%lld\n",ans);
if(m==0) break;
int x;
scanf("%lld",&x);
ll move=(ans+x)%n;
// cout<<move<<endl;
// id=(id+move+1)%n+1;
id=(id+move)%n;
}while(m--);
}
signed main(){
int _=1;
// cin>>_;
while(_--){
__();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 10008kb
input:
5 4 1 2 3 4 5 1 2 3 4 5 6 6 8 10
output:
10 10 13 21 36
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 10012kb
input:
1 100 9139 1 815121916 455099013 31761433 46418945 11466871 709189476 658667824 977821005 511405192 843598992 501074199 638564514 680433292 994431111 584582554 452689372 642414314 863578235 135133204 438404803 67246919 492858783 447116205 723252212 948645336 191050463 326944894 685212650 828613990 1...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 101 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 10036kb
input:
2 100 9859 8096 2 1 692572036 546897526 810778144 630776743 411450468 47253421 344401774 898201838 853758724 613913038 441359030 921437570 855535818 106915566 108572797 533697405 315571976 503278469 849317884 327448764 867873746 718830950 808828124 547579134 751502930 595486247 629024078 79153124 34...
output:
3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108...
result:
ok 101 lines
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 9900kb
input:
3 100 5987 4237 8891 3 1 2 760669141 361439344 393719043 515372386 379329282 704177992 446687639 688441074 939269095 570763162 492018656 161714447 596461367 384092911 304150759 54574629 350079205 804917425 296791887 311704304 120533843 281070757 787668201 311851357 243944555 860970785 463288414 9962...
output:
33155432 33155432 33155432 38526148 51752648 33155432 33155432 51752648 33155432 33155432 33155432 51752648 38526148 38526148 51752648 51752648 33155432 33155432 33155432 38526148 38526148 38526148 51752648 33155432 33155432 51752648 38526148 51752648 33155432 38526148 33155432 38526148 33155432 517...
result:
wrong answer 4th lines differ - expected: '46381932', found: '38526148'