Submission #69875903
Source Code Expand
/* Code By WCM */
/*
Date:
大致思路:
复杂度:
期望得分:
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <vector>
#include <queue>
#include <cmath>
#define int long long
using namespace std;
inline int read();
void write(int);
void writeln(int);
const int N = 3e5 + 5, B = 800, inf = 1e18;
struct D {
int a[B], siz, mnv, mxv, sum;
bool fl;
} bl[B];
int st[B], ed[B], cnt = 0, Size = 0;
void rebuild(int idx) {
D& blo = bl[idx];
blo.mnv = inf, blo.mxv = -inf, blo.sum = 0, blo.fl = 1;
for(int i = 0; i < blo.siz; i++) {
int vl = blo.a[i];
blo.fl = (vl > 0 ? 0 : blo.fl), blo.mnv = min(blo.mnv, vl), blo.mxv = max(blo.mxv, vl), blo.sum += vl;
}
if(blo.mnv == inf) blo.mnv = blo.mxv = 0;
}
void init(int A[], int n) {
Size = sqrt(n) + 1, cnt = (n + Size - 1) / Size;
for(int i = 0; i < cnt; i++) {
st[i] = i * Size, ed[i] = min((i + 1) * Size - 1, n - 1), bl[i].siz = ed[i] - st[i] + 1;
for(int j = 0; j < bl[i].siz; j++) bl[i].a[j] = A[st[i] + j];
rebuild(i);
}
}
int modify(int idx, int Ql, int Qr, int k) {
D& blo = bl[idx];
if(blo.fl) return 0;
int L = st[idx], R = ed[idx], cc = 0;
for(int i = max(L, Ql); i <= min(R, Qr); i++) {
int id = i - L, bc = min(blo.a[id], k);
cc += bc, blo.a[id] -= bc;
}
rebuild(idx);
return cc;
}
int update(int idx, int k) {
D& blo = bl[idx];
if(blo.fl) return 0;
if(blo.mnv >= k) {
int cc = k * blo.siz;
for(int i = 0; i < blo.siz; i++) blo.a[i] -= k;
blo.mnv -= k, blo.mxv -= k, blo.sum -= cc;
if(blo.mnv == 0) blo.fl = 1;
return cc;
}
else if(blo.mxv <= k) {
int cc = blo.sum;
for(int i = 0; i < blo.siz; i++) blo.a[i] = 0;
blo.mnv = blo.mxv = blo.sum = 0, blo.fl = 1;
return cc;
}
else {
int cc = 0;
for(int i = 0; i < blo.siz; i++) {
int bc = min(blo.a[i], k);
cc += bc, blo.a[i] -= bc;
}
rebuild(idx);
return cc;
}
}
int query(int l, int r, int k) {
int ret = 0;
for(int i = 0; i < cnt; i++) {
if(st[i] > r) break;
if(ed[i] < l) continue;
if(l <= st[i] && ed[i] <= r) ret += update(i, k);
else ret += modify(i, l, r, k);
}
return ret;
}
int n, Q, A[N];
signed main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
n = read();
for(int i = 0; i < n; i++) A[i] = read();
init(A, n);
Q = read();
for(int i = 0; i < Q; i++) {
int l = read() - 1, r = read() - 1, k = read();
printf("%lld\n", query(l, r, k));
}
// printf("\nThe time used: ");
// printf("%.2lfs",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
inline int read() {
int res = 0, f = 1;
char ch = getchar();
while( !(ch >= '0' && ch <= '9') ) {
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
res = (res << 1) + (res << 3) + (ch ^ 48);
ch = getchar();
}
return res * f;
}
void write(int x) {
static int sta[35];
int top = 0;
do {
sta[top++] = x % 10;
x /= 10;
} while(x);
while(top) putchar(sta[--top] ^ 48);
}
void writeln(int x) {
write(x);
putchar('\n');
}
Submission Info
| Submission Time |
|
| Task |
F - Clearance |
| User |
WZwangchongming |
| Language |
C++ 20 (gcc 12.2) |
| Score |
0 |
| Code Size |
3475 Byte |
| Status |
WA |
| Exec Time |
5519 ms |
| Memory |
10180 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
0 / 525 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt |
| All |
sample_01.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt |
| Case Name |
Status |
Exec Time |
Memory |
| sample_01.txt |
AC |
1 ms |
3728 KiB |
| test_01.txt |
AC |
1 ms |
3724 KiB |
| test_02.txt |
AC |
1 ms |
3636 KiB |
| test_03.txt |
AC |
1 ms |
3696 KiB |
| test_04.txt |
AC |
34 ms |
3788 KiB |
| test_05.txt |
AC |
31 ms |
3724 KiB |
| test_06.txt |
AC |
29 ms |
3716 KiB |
| test_07.txt |
TLE |
5518 ms |
9260 KiB |
| test_08.txt |
AC |
885 ms |
9480 KiB |
| test_09.txt |
AC |
516 ms |
9496 KiB |
| test_10.txt |
TLE |
5518 ms |
9152 KiB |
| test_11.txt |
TLE |
5515 ms |
9216 KiB |
| test_12.txt |
TLE |
5518 ms |
9216 KiB |
| test_13.txt |
TLE |
5518 ms |
9220 KiB |
| test_14.txt |
TLE |
5515 ms |
9160 KiB |
| test_15.txt |
TLE |
5518 ms |
9168 KiB |
| test_16.txt |
TLE |
5515 ms |
9200 KiB |
| test_17.txt |
TLE |
5518 ms |
9236 KiB |
| test_18.txt |
TLE |
5518 ms |
9168 KiB |
| test_19.txt |
TLE |
5518 ms |
9236 KiB |
| test_20.txt |
TLE |
5518 ms |
9216 KiB |
| test_21.txt |
TLE |
5518 ms |
9232 KiB |
| test_22.txt |
WA |
436 ms |
9500 KiB |
| test_23.txt |
WA |
440 ms |
9568 KiB |
| test_24.txt |
WA |
450 ms |
9560 KiB |
| test_25.txt |
WA |
438 ms |
9512 KiB |
| test_26.txt |
TLE |
5519 ms |
9156 KiB |
| test_27.txt |
AC |
1780 ms |
10180 KiB |
| test_28.txt |
TLE |
5518 ms |
9224 KiB |
| test_29.txt |
TLE |
5518 ms |
9260 KiB |
| test_30.txt |
TLE |
5515 ms |
9216 KiB |
| test_31.txt |
TLE |
5518 ms |
9200 KiB |
| test_32.txt |
TLE |
5518 ms |
9180 KiB |
| test_33.txt |
TLE |
5518 ms |
9228 KiB |
| test_34.txt |
TLE |
5518 ms |
9072 KiB |
| test_35.txt |
TLE |
5518 ms |
9312 KiB |
| test_36.txt |
TLE |
5515 ms |
9256 KiB |
| test_37.txt |
TLE |
5518 ms |
9156 KiB |