QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#233992#7072. PhotographstcmuyiWA 0ms3640kbC++201.7kb2023-11-01 12:20:522023-11-01 12:20:53

Judging History

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

  • [2023-11-01 12:20:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3640kb
  • [2023-11-01 12:20:52]
  • 提交

answer

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define i64 long long
#define endl '\n'
#define lb(x) ((x) & (-x))
using namespace std;
const i64 mod = 1e9+7;
const int maxn = 1e4+10;
signed main()
{
    IOS;
    int n,q; cin >> n >> q;
    vector<i64> h(n+1);
    for(int i = 1; i <= n; ++i) cin >> h[i];
    vector<int> p(n+1);
    for(int i = 1; i <= n; ++i)  cin >> p[i];
    auto ck = [&](int x) -> i64
    {
        set<int> st;
        i64 ans = 0,sum = 0;
        vector<int> id(n+1);
        int idx = 0;
        for(int i = x; i <= n; ++i) id[++idx] = p[i];
        for(int i = 1; i < x; ++i) id[++idx] = p[i];
        for(int i = 1; i <= n; ++i)
        {
            st.insert(id[i]);
            auto it = st.lower_bound(id[i]);
            if(it != st.begin())
            {
                int l = *prev(it);
                ans = (ans + (h[l] - h[id[i]]) * (h[l] - h[id[i]])) % mod;
            }
            if(next(it) != st.end())
            {
                int r = *next(it);
                ans = (ans + (h[r] - h[id[i]]) * (h[r] - h[id[i]])) % mod;
            }
            if(it != st.begin() && next(it) != st.end())
            {
                int l = *prev(it);
                int r = *next(it);
                ans = (ans - (h[r] - h[l]) * (h[r] - h[l]) + mod) % mod;
            }
            sum = (sum + ans) % mod;
        }
        return sum;
    };
    i64 ans = ck(1);
    int top = 1;
    while(q--)
    {
        int k; cin >> k;
        top = (top - 1 + k + ans) % n + 1;
        ans = ck(top);
        cout << ans << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3640kb

input:

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

output:

10
13
21
36

result:

wrong answer 2nd lines differ - expected: '10', found: '13'