QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#694909 | #7072. Photograph | RainingLove | WA | 1ms | 5672kb | C++23 | 2.9kb | 2024-10-31 18:55:52 | 2024-10-31 18:55:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
int n,q;
int h[100005];
int cnt[10004];
int p[200005];
list<int>::iterator it[10004];
void solve() {
cin>>n>>q;
ll sum=0;
for(int i=1;i<=n;i++) {
cin>>h[i];
cnt[h[i]]++;
}
for(int i=1;i<=n;i++) {
cin>>p[i];
p[i+n]=p[i];
}
ll lastans=0;
list<int> q;
ll tmp=0;
ll g=-1;
for(int i=1;i<=10000;i++) {
if(cnt[i]) {
q.push_back(i);
it[i]=(--q.end());
if(g==-1)g=i;
else {
sum+=(ll)(i-g)*(i-g);
g=i;
}
}
}
for(int i=n+tmp;i>=1+tmp;i--) {
lastans+=sum;
cnt[h[p[i]]]--;
if(cnt[h[p[i]]]==0) {
auto now=it[h[p[i]]];
if(next(now)!=q.end() && now!=q.begin()) {
ll lst=*prev(now);
ll nxt=*next(now);
sum+=(nxt-lst)*(nxt-lst);
}
if(next(now)!=q.end()) {
ll nxt=*next(now);
ll nw=h[p[i]];
sum-=(nxt-nw)*(nxt-nw);
}
if(now!=q.begin()) {
ll lst=*prev(now);
ll nw=h[p[i]];
sum-=(nw-lst)*(nw-lst);
}
q.erase(it[h[p[i]]]);
}
}
cout<<lastans<<'\n';
for(int i=1;i<=::q;i++) {
ll k; cin>>k;
tmp=(tmp+lastans+k)%n;
lastans=0;
ll sum=0;
for(int i=1;i<=n;i++) {
cnt[h[i]]++;
}
list<int> q;
ll g=-1;
for(int i=1;i<=10000;i++) {
if(cnt[i]) {
q.push_back(i);
it[i]=(--q.end());
if(g==-1)g=i;
else {
sum+=(ll)(i-g)*(i-g);
g=i;
}
}
}
for(int i=n+tmp;i>=1+tmp;i--) {
lastans+=sum;
cnt[h[p[i]]]--;
if(cnt[h[p[i]]]==0) {
auto now=it[h[p[i]]];
if(next(now)!=q.end() && now!=q.begin()) {
ll lst=*prev(now);
ll nxt=*next(now);
sum+=(nxt-lst)*(nxt-lst);
}
if(next(now)!=q.end()) {
ll nxt=*next(now);
ll nw=h[p[i]];
sum-=(nxt-nw)*(nxt-nw);
}
if(now!=q.begin()) {
ll lst=*prev(now);
ll nw=h[p[i]];
sum-=(nw-lst)*(nw-lst);
}
q.erase(it[h[p[i]]]);
}
}
cout<<lastans<<'\n';
}
}
/*
*/
signed main() {
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
while(t--)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5672kb
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: 3636kb
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: 3896kb
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: 3644kb
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:
19928932 33155432 33155432 14558216 14558216 19928932 33155432 19928932 14558216 14558216 14558216 33155432 19928932 19928932 33155432 33155432 14558216 14558216 14558216 19928932 19928932 19928932 33155432 14558216 14558216 33155432 19928932 33155432 14558216 19928932 14558216 19928932 14558216 331...
result:
wrong answer 1st lines differ - expected: '33155432', found: '19928932'