QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#118782#6675. DS Team Selection 2xaphoenixWA 2ms22084kbC++143.1kb2023-07-04 04:08:412023-07-04 04:08:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-04 04:08:44]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:22084kb
  • [2023-07-04 04:08:41]
  • 提交

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, flag;
LL add[M], cov[M], sum[M], rval[M], lval[M];
LL a[N], cnt, len1[M], len2[M], al[M], ar[M], tot, num;

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], tot += a[i], num += i;
	// build(1, 1, n);
	while (m--) {
		int op;
		cin >> op;
		if (op == 1) {
			LL mn;
			cin >> mn;
			if (!flag) {
				flag = 1;
				repn(i, 1, n) a[i] = min(a[i] + cnt * i, mn);
				build(1, 1, n);
			}
			change1(1, 1, n, mn);
		}
		else if (op == 2) {
			if (!flag) cnt++;
			else apply_add(1, 1);
		}
		else {
			int l, r;
			cin >> l >> r;
			if (!flag) cout << tot + cnt * num << "\n";
			else {
				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: 0ms
memory: 21764kb

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: 2ms
memory: 22084kb

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:

512185934
455189773
121665669
479780036
365384860
46972576
447479086
699980333
227511280
42840171
484718304
1128621587
273143655
2203656
392858511
222306650
20745327
108789072
22115640
34631220
55848925
92367865
36949030
86469096
43551820
50829332
1334865
76074390
114623436
13564322
79974466
1523008...

result:

wrong answer 4th numbers differ - expected: '408693244', found: '479780036'