QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#410282 | #7072. Photograph | Liuhao | WA | 1ms | 3736kb | C++23 | 1.8kb | 2024-05-13 20:44:24 | 2024-05-13 20:44:25 |
Judging History
answer
//
// Created by liuhao on 2024/5/13.
//
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;
#define PII pair<int,int>
#define fi first
#define se second
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define endl '\n'
#define vii vector<vector<int>>
char *p1, *p2, buf[100000];
#define getcar() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
inline int read() {
int x = 0, f = 1, c = getcar();
while (!(c<='9'&&c>='0')) f = (c == '-' ? -f : f), c = getcar();
while (c<='9'&&c>='0') x = x * 10 + c - '0', c = getcar();
return x * f;
}
struct Node{
int l,r,data;
};
#define re read()
signed main() {
#ifdef Liuhao
freopen("in.txt", "r", stdin);
#else
ios;
#endif
int n=re,q=re;
vector<int>a(n + 2);
vector<int>h(n + 2);
vector<int>st(n+1);
for(int i=1;i<=n;i++){
h[i]=re;
}
for (int i = 1; i <= n; i++) {
a[i]=re;
st[a[i]]=h[i];
}
int last=0;
int k=0;
auto get=[&](int i){//第i次进入的学号
return a[(i+k-1)%n+1];
};
auto cal=[&](int i,int j){
return (i-j)*(i-j);
};
auto solve=[&](){
vector<int>l(n+2);
vector<int>r(n+2);
for(int j=1;j<=n+1;j++)l[j]=j-1;
for(int j=0;j<=n;j++)r[j]=j+1;
int res=0;
for(int i=2;i<=n;i++){
res+=cal(st[i],st[i-1]);
}
int ans=res;
for(int j=n;j>=1;j--){
int now=get(j);
int pre=l[now];
int nex=r[now];
if(pre!=0)res-=cal(st[now],st[pre]);
if(nex!=n+1)res-=cal(st[now],st[nex]);
if(pre!=0&&nex!=n+1)res+=cal(st[pre],st[nex]);
ans+=res;
l[r[now]]=l[now];
r[l[now]]=r[now];
}
k+=ans;
cout<<ans<<endl;
};
solve();
for(int i=1;i<=q;i++){
k+=re;
k+=last;
k%=n;
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3536kb
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: 0ms
memory: 3736kb
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: 0ms
memory: 3492kb
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: 0ms
memory: 3524kb
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'