QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#282444#7072. PhotographVladMTL 0ms0kbC++202.1kb2023-12-12 01:16:022023-12-12 01:16:02

Judging History

你现在查看的是最新测评结果

  • [2023-12-12 01:16:02]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-12-12 01:16:02]
  • 提交

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(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;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

5 4
1 2 3 4 5
1 2 3 4 5
6
6
8
10

output:


result: