QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#118781 | #6675. DS Team Selection 2 | xaphoenix | WA | 4ms | 22112kb | C++14 | 2.9kb | 2023-07-04 03:17:36 | 2023-07-04 03:17:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define LC k<<1
#define RC k<<1|1
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repn(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = (n) - 1; i >= a; i--)
#define pern(i, a, n) for (int i = n; i >= a; i--)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef pair<double, double> PDD;
typedef pair<ull, ull> PUU;
typedef pair<LL, LL> PLL;
const int N = 210000;
const int M = 1100000;
const int mod = 1e9+7;
const int inf = (int)1e9;
const LL INF = 1e18;
const double eps = 1e-9;
mt19937_64 Rand((unsigned long long)new char);
#define rand Rand
int n, m;
LL add[M], cov[M], sum[M], rval[M], lval[M];
LL a[N], len1[M], len2[M], al[M], ar[M];
void update(int k) {
sum[k] = sum[LC] + sum[RC];
len1[k] = len1[LC] + len1[RC];
len2[k] = len2[LC] + len2[RC];
lval[k] = lval[LC];
rval[k] = rval[RC];
}
void apply_cov(int k, LL v) {
sum[k] = len1[k] * v;
lval[k] = rval[k] = v;
add[k] = 0;
cov[k] = v;
}
void apply_add(int k, LL v) {
sum[k] += len2[k] * v;
rval[k] += ar[k] * v;
lval[k] += al[k] * v;
add[k] += v;
}
void pushdown(int k) {
if (cov[k] != -1) {
apply_cov(LC, cov[k]);
apply_cov(RC, cov[k]);
cov[k] = -1;
}
if (add[k]) {
apply_add(LC, add[k]);
apply_add(RC, add[k]);
add[k] = 0;
}
}
void build(int k, int l, int r) {
al[k] = l, ar[k] = r;
cov[k] = -1;
if (l == r) {
sum[k] = a[l];
len1[k] = 1;
len2[k] = l;
lval[k] = rval[k] = a[l];
return;
}
int mid = (l + r) / 2;
build(LC, l, mid);
build(RC, mid + 1, r);
update(k);
}
void change1(int k, int l, int r, LL v) {
if (rval[k] <= v) return;
if (lval[k] >= v) {
apply_cov(k, v);
return;
}
pushdown(k);
int mid = (l + r) / 2;
if (lval[RC] <= v) change1(RC, mid + 1, r, v);
else apply_cov(RC, v), change1(LC, l, mid, v);
update(k);
}
LL ask(int k, int l, int r, int a, int b) {
if (l == a && r == b) return sum[k];
int mid = (l + r) / 2;
pushdown(k);
if (b <= mid) return ask(LC, l, mid, a, b);
else if (a > mid) return ask(RC, mid + 1, r, a, b);
else return ask(LC, l, mid, a, mid) + ask(RC, mid + 1, r, mid + 1, b);
}
int main() {
IO;
cin >> n >> m;
repn(i, 1, n) cin >> a[i];
build(1, 1, n);
while (m--) {
int op;
cin >> op;
if (op == 1) {
LL mn;
cin >> mn;
change1(1, 1, n, mn);
}
else if (op == 2) apply_add(1, 1);
else {
int l, r;
cin >> l >> r;
LL res = ask(1, 1, n, l, r);
cout << res << "\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 21820kb
input:
13 11 6 14 14 6 3 6 4 13 10 3 12 5 11 1 2 2 2 2 1 11 3 4 6 2 1 6 2 1 9 3 2 13
output:
33 107
result:
ok 2 number(s): "33 107"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 22112kb
input:
5000 5000 29940 259997 53132 912489 608312 594283 432259 344137 889466 383028 320097 337418 571199 372832 563110 542407 133378 998389 238387 120880 477310 634888 191990 133585 935315 558139 141724 893331 190118 991968 843042 384930 935256 891482 123419 91431 955722 376987 197566 106433 234494 645967...
output:
603238172 647825607 173911092 481824041 380349966 46972576 490830837 787469179 227511280 42840171 515350004 1307955231 294226664 2203656 417840735 222306650 20745327 108789072 22115640 34631220 55848925 92367865 36949030 86469096 43551820 50829332 1334865 76074390 114623436 13564322 79974466 1523008...
result:
wrong answer 1st numbers differ - expected: '512185934', found: '603238172'