답안 #237134

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
237134 2020-06-04T17:50:42 Z islingr Fire (JOI20_ho_t5) C++14
100 / 100
604 ms 41724 KB
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

#define rep(i, a, b) for (auto i = (a); i <= (b); ++i)
#define trav(x, v) for (auto &x : v)
#define eb(x...) emplace_back(x)
#define all(x) begin(x), end(x)
#define lb(x...) lower_bound(x)

using ll = int64_t;

struct S {
	int n; vector<ll> t;
	S(int n = 0) : n{n}, t(2 * n, 0) { } 
	ll query(int r) {
		ll s = 0; int l = n;
		for (r += n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) s += t[l++];
			if (r & 1) s += t[--r];
		}
		return s;
	}
	void add(int p, ll v) {
		for (t[p += n] += v; p >>= 1; )
			t[p] = t[p << 1|0] + t[p << 1|1];
	}
};

const int N = 13 << 14;
int s[N], p[N], nxt[N], t[N];
ll ans[N], pref[N];
vector<int> e[N], g[N];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, m; cin >> n >> m;
	rep(i, 1, n) {
		cin >> s[i];
		pref[i] = pref[i - 1] + s[i];

		p[i] = i - 1; nxt[i] = n + 1;
		while (p[i] && s[p[i]] < s[i])
			nxt[p[i]] = i, p[i] = p[p[i]];
	}
	rep(i, 1, n) if (!p[i]) p[i] = i;

	rep(i, 1, m) {
		int l, r; cin >> t[i] >> l >> r;
		e[l - 1].eb(-i); e[r].eb(i);
	}

	vector<int> a;
	rep(i, 1, n) {
		while(!a.empty() && s[a.back()] < s[i]) a.pop_back();
		a.eb(i);
		trav(j, e[i]) {
			int prev = *lb(all(a), i - t[abs(j)]);
			ll del = 1ll * s[prev] * (i - prev) + pref[prev];
			if (j < 0) ans[-j] -= del;
			else ans[j] += del;
			g[prev].eb(j);
		}
	}

	S U(n), US(n), D(n), DS(n);
	rep(i, 1, n) {
		ll w = s[p[i]] - s[i];
		int u = i - p[i] - 1, d = nxt[i] - p[i] - 1;
		US.add(u, w * u); U.add(u, w);
		DS.add(d, w * d); D.add(d, w);
		trav(j, g[i]) {
			int t = ::t[abs(j)];
			ll del = 0;
			del += U.query(t) * t - US.query(t);
			del += DS.query(t) - D.query(t) * t;
			if (j < 0) ans[-j] -= del;
			else ans[j] += del;
		}
	}

	rep(i, 1, m) cout << ans[i] << '\n';	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10368 KB Output is correct
2 Correct 11 ms 10368 KB Output is correct
3 Correct 13 ms 10368 KB Output is correct
4 Correct 11 ms 10368 KB Output is correct
5 Correct 11 ms 10496 KB Output is correct
6 Correct 11 ms 10368 KB Output is correct
7 Correct 10 ms 10368 KB Output is correct
8 Correct 11 ms 10368 KB Output is correct
9 Correct 11 ms 10496 KB Output is correct
10 Correct 11 ms 10496 KB Output is correct
11 Correct 11 ms 10496 KB Output is correct
12 Correct 11 ms 10368 KB Output is correct
13 Correct 11 ms 10368 KB Output is correct
14 Correct 12 ms 10496 KB Output is correct
15 Correct 11 ms 10368 KB Output is correct
16 Correct 11 ms 10496 KB Output is correct
17 Correct 12 ms 10368 KB Output is correct
18 Correct 11 ms 10368 KB Output is correct
19 Correct 11 ms 10368 KB Output is correct
20 Correct 11 ms 10496 KB Output is correct
21 Correct 11 ms 10368 KB Output is correct
22 Correct 10 ms 10368 KB Output is correct
23 Correct 11 ms 10368 KB Output is correct
24 Correct 10 ms 10368 KB Output is correct
25 Correct 11 ms 10368 KB Output is correct
26 Correct 11 ms 10368 KB Output is correct
27 Correct 11 ms 10368 KB Output is correct
28 Correct 11 ms 10496 KB Output is correct
29 Correct 11 ms 10368 KB Output is correct
30 Correct 11 ms 10496 KB Output is correct
31 Correct 12 ms 10368 KB Output is correct
32 Correct 13 ms 10368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10368 KB Output is correct
2 Correct 314 ms 41324 KB Output is correct
3 Correct 292 ms 40808 KB Output is correct
4 Correct 318 ms 41392 KB Output is correct
5 Correct 317 ms 41644 KB Output is correct
6 Correct 282 ms 41140 KB Output is correct
7 Correct 335 ms 41720 KB Output is correct
8 Correct 308 ms 41712 KB Output is correct
9 Correct 317 ms 41724 KB Output is correct
10 Correct 313 ms 40744 KB Output is correct
11 Correct 294 ms 41348 KB Output is correct
12 Correct 308 ms 40584 KB Output is correct
13 Correct 307 ms 41332 KB Output is correct
14 Correct 291 ms 41260 KB Output is correct
15 Correct 309 ms 41524 KB Output is correct
16 Correct 288 ms 41296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10368 KB Output is correct
2 Correct 444 ms 40428 KB Output is correct
3 Correct 433 ms 39820 KB Output is correct
4 Correct 439 ms 40936 KB Output is correct
5 Correct 442 ms 40108 KB Output is correct
6 Correct 449 ms 40552 KB Output is correct
7 Correct 436 ms 40492 KB Output is correct
8 Correct 446 ms 40348 KB Output is correct
9 Correct 453 ms 40064 KB Output is correct
10 Correct 442 ms 40076 KB Output is correct
11 Correct 454 ms 40476 KB Output is correct
12 Correct 420 ms 39800 KB Output is correct
13 Correct 459 ms 40192 KB Output is correct
14 Correct 465 ms 39716 KB Output is correct
15 Correct 454 ms 40300 KB Output is correct
16 Correct 434 ms 39916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 595 ms 40592 KB Output is correct
2 Correct 545 ms 40536 KB Output is correct
3 Correct 563 ms 41160 KB Output is correct
4 Correct 604 ms 40428 KB Output is correct
5 Correct 587 ms 40728 KB Output is correct
6 Correct 562 ms 40620 KB Output is correct
7 Correct 560 ms 41060 KB Output is correct
8 Correct 565 ms 40804 KB Output is correct
9 Correct 583 ms 40556 KB Output is correct
10 Correct 565 ms 40772 KB Output is correct
11 Correct 603 ms 40660 KB Output is correct
12 Correct 587 ms 40808 KB Output is correct
13 Correct 563 ms 40816 KB Output is correct
14 Correct 590 ms 40804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10368 KB Output is correct
2 Correct 11 ms 10368 KB Output is correct
3 Correct 13 ms 10368 KB Output is correct
4 Correct 11 ms 10368 KB Output is correct
5 Correct 11 ms 10496 KB Output is correct
6 Correct 11 ms 10368 KB Output is correct
7 Correct 10 ms 10368 KB Output is correct
8 Correct 11 ms 10368 KB Output is correct
9 Correct 11 ms 10496 KB Output is correct
10 Correct 11 ms 10496 KB Output is correct
11 Correct 11 ms 10496 KB Output is correct
12 Correct 11 ms 10368 KB Output is correct
13 Correct 11 ms 10368 KB Output is correct
14 Correct 12 ms 10496 KB Output is correct
15 Correct 11 ms 10368 KB Output is correct
16 Correct 11 ms 10496 KB Output is correct
17 Correct 12 ms 10368 KB Output is correct
18 Correct 11 ms 10368 KB Output is correct
19 Correct 11 ms 10368 KB Output is correct
20 Correct 11 ms 10496 KB Output is correct
21 Correct 11 ms 10368 KB Output is correct
22 Correct 10 ms 10368 KB Output is correct
23 Correct 11 ms 10368 KB Output is correct
24 Correct 10 ms 10368 KB Output is correct
25 Correct 11 ms 10368 KB Output is correct
26 Correct 11 ms 10368 KB Output is correct
27 Correct 11 ms 10368 KB Output is correct
28 Correct 11 ms 10496 KB Output is correct
29 Correct 11 ms 10368 KB Output is correct
30 Correct 11 ms 10496 KB Output is correct
31 Correct 12 ms 10368 KB Output is correct
32 Correct 13 ms 10368 KB Output is correct
33 Correct 495 ms 40232 KB Output is correct
34 Correct 522 ms 40588 KB Output is correct
35 Correct 535 ms 40492 KB Output is correct
36 Correct 533 ms 40504 KB Output is correct
37 Correct 508 ms 40336 KB Output is correct
38 Correct 557 ms 40556 KB Output is correct
39 Correct 590 ms 40120 KB Output is correct
40 Correct 551 ms 39884 KB Output is correct
41 Correct 552 ms 40492 KB Output is correct
42 Correct 500 ms 40084 KB Output is correct
43 Correct 430 ms 40440 KB Output is correct
44 Correct 421 ms 40816 KB Output is correct
45 Correct 424 ms 39720 KB Output is correct
46 Correct 423 ms 40200 KB Output is correct
47 Correct 415 ms 39688 KB Output is correct
48 Correct 413 ms 39400 KB Output is correct
49 Correct 428 ms 40072 KB Output is correct
50 Correct 452 ms 40492 KB Output is correct
51 Correct 431 ms 40456 KB Output is correct
52 Correct 422 ms 40040 KB Output is correct
53 Correct 417 ms 39928 KB Output is correct
54 Correct 395 ms 39928 KB Output is correct
55 Correct 419 ms 40136 KB Output is correct
56 Correct 397 ms 40308 KB Output is correct
57 Correct 425 ms 39928 KB Output is correct
58 Correct 449 ms 40260 KB Output is correct
59 Correct 314 ms 41324 KB Output is correct
60 Correct 292 ms 40808 KB Output is correct
61 Correct 318 ms 41392 KB Output is correct
62 Correct 317 ms 41644 KB Output is correct
63 Correct 282 ms 41140 KB Output is correct
64 Correct 335 ms 41720 KB Output is correct
65 Correct 308 ms 41712 KB Output is correct
66 Correct 317 ms 41724 KB Output is correct
67 Correct 313 ms 40744 KB Output is correct
68 Correct 294 ms 41348 KB Output is correct
69 Correct 308 ms 40584 KB Output is correct
70 Correct 307 ms 41332 KB Output is correct
71 Correct 291 ms 41260 KB Output is correct
72 Correct 309 ms 41524 KB Output is correct
73 Correct 288 ms 41296 KB Output is correct
74 Correct 444 ms 40428 KB Output is correct
75 Correct 433 ms 39820 KB Output is correct
76 Correct 439 ms 40936 KB Output is correct
77 Correct 442 ms 40108 KB Output is correct
78 Correct 449 ms 40552 KB Output is correct
79 Correct 436 ms 40492 KB Output is correct
80 Correct 446 ms 40348 KB Output is correct
81 Correct 453 ms 40064 KB Output is correct
82 Correct 442 ms 40076 KB Output is correct
83 Correct 454 ms 40476 KB Output is correct
84 Correct 420 ms 39800 KB Output is correct
85 Correct 459 ms 40192 KB Output is correct
86 Correct 465 ms 39716 KB Output is correct
87 Correct 454 ms 40300 KB Output is correct
88 Correct 434 ms 39916 KB Output is correct
89 Correct 595 ms 40592 KB Output is correct
90 Correct 545 ms 40536 KB Output is correct
91 Correct 563 ms 41160 KB Output is correct
92 Correct 604 ms 40428 KB Output is correct
93 Correct 587 ms 40728 KB Output is correct
94 Correct 562 ms 40620 KB Output is correct
95 Correct 560 ms 41060 KB Output is correct
96 Correct 565 ms 40804 KB Output is correct
97 Correct 583 ms 40556 KB Output is correct
98 Correct 565 ms 40772 KB Output is correct
99 Correct 603 ms 40660 KB Output is correct
100 Correct 587 ms 40808 KB Output is correct
101 Correct 563 ms 40816 KB Output is correct
102 Correct 590 ms 40804 KB Output is correct