QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#395754 | #7072. Photograph | suibian_xiaozhao | WA | 2ms | 11764kb | C++23 | 2.3kb | 2024-04-21 18:09:12 | 2024-04-21 18:09:13 |
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 >> p[i];
p[i] --;
}
irep(i, 0, n - 1){
cin >> h[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(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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11764kb
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: 7760kb
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: -100
Wrong Answer
time: 1ms
memory: 5688kb
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:
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
wrong answer 1st lines differ - expected: '3108169', found: '0'