QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#152669 | #7072. Photograph | PetroTarnavskyi# | WA | 1ms | 5724kb | C++17 | 1.6kb | 2023-08-28 16:39:33 | 2023-08-28 16:39:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FILL(a, b) memset(a, b, sizeof(a))
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int MAX = 1 << 17;
int h[MAX], p[MAX], sorted[MAX], prv[MAX], nxt[MAX], np[MAX];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
FOR(i, 0, n)
cin >> h[i];
FOR(i, 0, n)
{
cin >> p[i];
p[i]--;
}
iota(sorted, sorted + n, 0);
sort(sorted, sorted + n, [](int i, int j) {return h[i] < h[j];});
LL lastans = 0, k = 0;
FOR(i, 0, q + 1)
{
if (i != 0)
cin >> k;
k += lastans;
FOR(j, 0, n)
{
np[j] = p[(j + k) % n];
}
FOR(j, 0, n)
p[j] = np[j];
lastans = 0;
LL sum = 0;
FOR(j, 0, n)
{
prv[sorted[j]] = j == 0 ? -1 : sorted[j - 1];
nxt[sorted[j]] = j == n - 1 ? -1 : sorted[j + 1];
if (j + 1 < n)
{
LL d = h[sorted[j + 1]] - h[sorted[j]];
sum += d * d;
}
}
RFOR(j, n, 0)
{
lastans += sum;
int pos = np[j];
int l = prv[pos];
int r = nxt[pos];
if (l != -1)
{
LL d = h[pos] - h[l];
sum -= d * d;
nxt[l] = r;
}
if (r != -1)
{
LL d = h[pos] - h[r];
sum -= d * d;
prv[r] = l;
}
if (l != -1 && r != -1)
{
LL d = h[l] - h[r];
sum += d * d;
}
}
cout << lastans << "\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5724kb
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: 3696kb
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: 0
Accepted
time: 1ms
memory: 5616kb
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:
3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108169 3108...
result:
ok 101 lines
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5648kb
input:
3 100 5987 4237 8891 3 1 2 760669141 361439344 393719043 515372386 379329282 704177992 446687639 688441074 939269095 570763162 492018656 161714447 596461367 384092911 304150759 54574629 350079205 804917425 296791887 311704304 120533843 281070757 787668201 311851357 243944555 860970785 463288414 9962...
output:
19928932 33155432 33155432 14558216 14558216 19928932 33155432 19928932 14558216 14558216 14558216 33155432 19928932 19928932 33155432 33155432 14558216 14558216 14558216 19928932 19928932 19928932 33155432 14558216 14558216 33155432 19928932 33155432 14558216 19928932 14558216 19928932 14558216 331...
result:
wrong answer 1st lines differ - expected: '33155432', found: '19928932'