QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282445 | #7072. Photograph | VladM | WA | 0ms | 3396kb | C++20 | 2.1kb | 2023-12-12 01:19:45 | 2023-12-12 01:19:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define DIM 100007
long long h[DIM], ans, sum, it1, it2;
int n, q, it, p[DIM], d;
set<int> s;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
for(int i = 1; i <= n; i++) cin >> h[i];
for(int i = 1; i <= n; i++) cin >> p[i];
it = 1;
for(int tst = 1; tst <= q + 1; tst++){
if(tst != 1){
cin >> d;
d += ans % n;
it = (it - 1 + d + n) % n + 1;
}
sum = 0;
ans = 0;
s.clear();
int lst = (it - 2 + n) % n + 1;
for(int i = it; i != lst; i++){
if(i > n) i -= n;
if(i == lst) break;
if(s.empty()){
s.insert(p[i]);
continue;
}
if(s.size() == 1){
it1 = *s.begin();
sum += (h[p[i]] - h[it1]) * (h[p[i]] - h[it1]);
ans += sum;
s.insert(p[i]);
continue;
}
it1 = *s.begin();
if(p[i] < it1){
//cout << it1 << ' ' << H[i] << endl;
sum += (h[p[i]] - h[it1]) * (h[p[i]] - h[it1]);
ans += sum;
s.insert(p[i]);
continue;
}
it1 = *(--s.end());
if(p[i] > it1){
//cout << it1 << ' ' << H[i] << endl;
sum += (h[p[i]] - h[it1]) * (h[p[i]] - h[it1]);
ans += sum;
s.insert(p[i]);
continue;
}
auto LB = s.lower_bound(p[i]);
it1 = *(LB);
it2 = *(--LB);
it1 = h[it1];
it2 = h[it2];
//cout << it1 << ' ' << H[i] << ' ' << it2 << endl;
sum -= (it1 - it2) * (it1 - it2);
sum += (h[p[i]] - it1) * (h[p[i]] - it1);
sum += (h[p[i]] - it2) * (h[p[i]] - it2);
ans += sum;
s.insert(p[i]);
}
cout << ans << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3396kb
input:
5 4 1 2 3 4 5 1 2 3 4 5 6 6 8 10
output:
6 9 9 32 6
result:
wrong answer 1st lines differ - expected: '10', found: '6'