QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#233992 | #7072. Photograph | stcmuyi | WA | 0ms | 3640kb | C++20 | 1.7kb | 2023-11-01 12:20:52 | 2023-11-01 12:20:53 |
Judging History
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;
}
详细
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'