QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395760 | #7072. Photograph | suibian_xiaozhao | WA | 1ms | 9852kb | C++23 | 2.4kb | 2024-04-21 18:14:29 | 2024-04-21 18:14:29 |
Judging History
answer
//
// Created by DELLPC on 24-4-21.
//
#include<bits/stdc++.h>
using namespace std;
#define irep(i, l, r) for(int i = l; i <= r; ++ i)
#define drep(i, r, l) for(int i = r; i >= l; -- i)
const int N = 500000 +7;
const int mod = 1000000000 + 7;
#define ll long long
#define LD double
int n, q, st;
ll p[N], h[N];
int fa[N], nxt[N], fs[N];
int find(int x){
if(fa[x] == x)return x;
fa[x] = find(fa[x]);
return fa[x];
}
void merge(int x, int y){
if(x < 0 || y < 0)return;
x = find(x), y = find(y);
if(fs[x] > fs[y])swap(x, y);
nxt[x] = nxt[y];
fa[y] = x;
}
ll val(int x){
x = find(x);
if(nxt[x] == n)return 0;
return (h[fs[x]] - h[nxt[x]]) * (h[fs[x]] - h[nxt[x]]);
}
void solve(){
//n, q;
cin >> n >> q;
ll base = 0, lastans = 0, sum = 0;
irep(i, 0, n - 1){
cin >> h[i];
}
irep(i, 0, n - 1){
cin >> p[i];
p[i] --;
}
irep(i, 0, n - 2){
base += (h[i] - h[i + 1]) * (h[i] - h[i + 1]);
}
// lastans = base;
sum = base;
irep(i, 0, n - 1){
fa[i] = i;
nxt[i] = i + 1, fs[i] = i;
}
for(int i = st - 1;;){
if(i == -1)i += n;
lastans += sum;
// cerr << sum << ' ';
sum -= val(p[i]);
if(p[i])sum -= val(p[i] - 1);
if(p[i])merge(p[i] - 1, p[i]);
if(p[i])sum += val(p[i]);
i = (i - 1 + n) % n;
if((i + 1) % n == (st))break;
}
// cerr << endl;
cout << lastans << '\n';
while(q --){
irep(i, 0, n - 1){
fa[i] = i;
nxt[i] = i + 1, fs[i] = i;
}
// sum = base;
int k0;
cin >> k0;
k0 += lastans;
st = (st + k0) % n;
lastans = 0;
sum = base;
// cerr << st << endl;
for(int i = st - 1;;){
lastans += sum;
// cerr << sum << ' ';
if(i == -1)i += n;
sum -= val(p[i]);
if(p[i])sum -= val(p[i] - 1);
if(p[i])merge(p[i] - 1, p[i]);
if(p[i])sum += val(p[i]);
i = (i - 1 + n) % n;
if((i + 1) % n == (st))break;
}
cout << lastans << '\n';
}
}
int main(){
int T = 1;
// cin >> T;
while(T --){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9780kb
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: 9852kb
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: 7724kb
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: 0
Accepted
time: 0ms
memory: 5628kb
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 46381932 33155432 46381932 33155432 27784716 27784716 46381932 33155432 27784716 33155432 27784716 46381932 33155432 46381932 33155432 33155432 46381932 27784716 33155432 33155432 46381932 33155432 27784716 33155432 33155432 46381932 46381932 46381932 46381932 46381932 277...
result:
ok 101 lines
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 7680kb
input:
4 100 9411 3081 2149 9907 2 4 1 3 890272966 654059361 166090080 333233666 911989359 541813943 232020213 717913040 277628991 24281180 424608385 453986387 234435555 940076771 584737344 285922050 322027160 55417534 219258279 944530197 902531317 204963356 159347669 59389769 496952588 412286058 62840111 ...
output:
234381540 194798256 175715644 175715644 214293312 234381540 175715644 234381540 234381540 175715644 175715644 234381540 175715644 194798256 214293312 214293312 175715644 175715644 214293312 234381540 214293312 194798256 194798256 175715644 234381540 234381540 194798256 214293312 194798256 234381540 ...
result:
wrong answer 3rd lines differ - expected: '163047900', found: '175715644'