답안 #237121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
237121 2020-06-04T17:38:06 Z islingr Fire (JOI20_ho_t5) C++14
100 / 100
682 ms 45172 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;
	for(int i = 1; i <= n; i++) {
		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 11 ms 10368 KB Output is correct
2 Correct 11 ms 10368 KB Output is correct
3 Correct 11 ms 10368 KB Output is correct
4 Correct 11 ms 10496 KB Output is correct
5 Correct 11 ms 10368 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 10368 KB Output is correct
10 Correct 11 ms 10368 KB Output is correct
11 Correct 10 ms 10368 KB Output is correct
12 Correct 10 ms 10368 KB Output is correct
13 Correct 10 ms 10368 KB Output is correct
14 Correct 10 ms 10368 KB Output is correct
15 Correct 10 ms 10368 KB Output is correct
16 Correct 11 ms 10368 KB Output is correct
17 Correct 11 ms 10368 KB Output is correct
18 Correct 11 ms 10496 KB Output is correct
19 Correct 11 ms 10368 KB Output is correct
20 Correct 10 ms 10368 KB Output is correct
21 Correct 11 ms 10496 KB Output is correct
22 Correct 11 ms 10368 KB Output is correct
23 Correct 11 ms 10368 KB Output is correct
24 Correct 11 ms 10440 KB Output is correct
25 Correct 11 ms 10496 KB Output is correct
26 Correct 10 ms 10368 KB Output is correct
27 Correct 10 ms 10368 KB Output is correct
28 Correct 10 ms 10368 KB Output is correct
29 Correct 10 ms 10368 KB Output is correct
30 Correct 10 ms 10368 KB Output is correct
31 Correct 11 ms 10496 KB Output is correct
32 Correct 10 ms 10496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 10368 KB Output is correct
2 Correct 298 ms 44524 KB Output is correct
3 Correct 296 ms 44008 KB Output is correct
4 Correct 307 ms 44716 KB Output is correct
5 Correct 295 ms 44972 KB Output is correct
6 Correct 312 ms 44336 KB Output is correct
7 Correct 309 ms 45172 KB Output is correct
8 Correct 301 ms 44948 KB Output is correct
9 Correct 300 ms 44796 KB Output is correct
10 Correct 306 ms 44068 KB Output is correct
11 Correct 327 ms 44808 KB Output is correct
12 Correct 295 ms 43980 KB Output is correct
13 Correct 294 ms 44404 KB Output is correct
14 Correct 285 ms 44208 KB Output is correct
15 Correct 297 ms 44468 KB Output is correct
16 Correct 275 ms 44372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 10368 KB Output is correct
2 Correct 441 ms 43628 KB Output is correct
3 Correct 437 ms 43020 KB Output is correct
4 Correct 431 ms 44140 KB Output is correct
5 Correct 441 ms 43052 KB Output is correct
6 Correct 423 ms 43752 KB Output is correct
7 Correct 428 ms 43700 KB Output is correct
8 Correct 437 ms 43672 KB Output is correct
9 Correct 467 ms 43260 KB Output is correct
10 Correct 453 ms 43036 KB Output is correct
11 Correct 445 ms 44188 KB Output is correct
12 Correct 436 ms 43500 KB Output is correct
13 Correct 464 ms 43988 KB Output is correct
14 Correct 484 ms 43472 KB Output is correct
15 Correct 475 ms 43996 KB Output is correct
16 Correct 450 ms 43596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 599 ms 42656 KB Output is correct
2 Correct 600 ms 42676 KB Output is correct
3 Correct 611 ms 43508 KB Output is correct
4 Correct 682 ms 42744 KB Output is correct
5 Correct 607 ms 42860 KB Output is correct
6 Correct 607 ms 42908 KB Output is correct
7 Correct 597 ms 43332 KB Output is correct
8 Correct 614 ms 43140 KB Output is correct
9 Correct 614 ms 42836 KB Output is correct
10 Correct 628 ms 43076 KB Output is correct
11 Correct 615 ms 43216 KB Output is correct
12 Correct 631 ms 43108 KB Output is correct
13 Correct 573 ms 42940 KB Output is correct
14 Correct 553 ms 43028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 10368 KB Output is correct
2 Correct 11 ms 10368 KB Output is correct
3 Correct 11 ms 10368 KB Output is correct
4 Correct 11 ms 10496 KB Output is correct
5 Correct 11 ms 10368 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 10368 KB Output is correct
10 Correct 11 ms 10368 KB Output is correct
11 Correct 10 ms 10368 KB Output is correct
12 Correct 10 ms 10368 KB Output is correct
13 Correct 10 ms 10368 KB Output is correct
14 Correct 10 ms 10368 KB Output is correct
15 Correct 10 ms 10368 KB Output is correct
16 Correct 11 ms 10368 KB Output is correct
17 Correct 11 ms 10368 KB Output is correct
18 Correct 11 ms 10496 KB Output is correct
19 Correct 11 ms 10368 KB Output is correct
20 Correct 10 ms 10368 KB Output is correct
21 Correct 11 ms 10496 KB Output is correct
22 Correct 11 ms 10368 KB Output is correct
23 Correct 11 ms 10368 KB Output is correct
24 Correct 11 ms 10440 KB Output is correct
25 Correct 11 ms 10496 KB Output is correct
26 Correct 10 ms 10368 KB Output is correct
27 Correct 10 ms 10368 KB Output is correct
28 Correct 10 ms 10368 KB Output is correct
29 Correct 10 ms 10368 KB Output is correct
30 Correct 10 ms 10368 KB Output is correct
31 Correct 11 ms 10496 KB Output is correct
32 Correct 10 ms 10496 KB Output is correct
33 Correct 524 ms 44200 KB Output is correct
34 Correct 538 ms 44812 KB Output is correct
35 Correct 527 ms 44476 KB Output is correct
36 Correct 511 ms 44344 KB Output is correct
37 Correct 503 ms 44300 KB Output is correct
38 Correct 514 ms 44748 KB Output is correct
39 Correct 504 ms 44228 KB Output is correct
40 Correct 497 ms 44108 KB Output is correct
41 Correct 520 ms 44592 KB Output is correct
42 Correct 489 ms 44392 KB Output is correct
43 Correct 472 ms 44792 KB Output is correct
44 Correct 436 ms 45144 KB Output is correct
45 Correct 445 ms 43952 KB Output is correct
46 Correct 450 ms 44500 KB Output is correct
47 Correct 409 ms 43916 KB Output is correct
48 Correct 434 ms 43748 KB Output is correct
49 Correct 416 ms 44300 KB Output is correct
50 Correct 489 ms 44948 KB Output is correct
51 Correct 444 ms 44936 KB Output is correct
52 Correct 438 ms 44260 KB Output is correct
53 Correct 447 ms 44280 KB Output is correct
54 Correct 398 ms 43872 KB Output is correct
55 Correct 387 ms 44128 KB Output is correct
56 Correct 398 ms 44404 KB Output is correct
57 Correct 418 ms 43924 KB Output is correct
58 Correct 428 ms 44664 KB Output is correct
59 Correct 298 ms 44524 KB Output is correct
60 Correct 296 ms 44008 KB Output is correct
61 Correct 307 ms 44716 KB Output is correct
62 Correct 295 ms 44972 KB Output is correct
63 Correct 312 ms 44336 KB Output is correct
64 Correct 309 ms 45172 KB Output is correct
65 Correct 301 ms 44948 KB Output is correct
66 Correct 300 ms 44796 KB Output is correct
67 Correct 306 ms 44068 KB Output is correct
68 Correct 327 ms 44808 KB Output is correct
69 Correct 295 ms 43980 KB Output is correct
70 Correct 294 ms 44404 KB Output is correct
71 Correct 285 ms 44208 KB Output is correct
72 Correct 297 ms 44468 KB Output is correct
73 Correct 275 ms 44372 KB Output is correct
74 Correct 441 ms 43628 KB Output is correct
75 Correct 437 ms 43020 KB Output is correct
76 Correct 431 ms 44140 KB Output is correct
77 Correct 441 ms 43052 KB Output is correct
78 Correct 423 ms 43752 KB Output is correct
79 Correct 428 ms 43700 KB Output is correct
80 Correct 437 ms 43672 KB Output is correct
81 Correct 467 ms 43260 KB Output is correct
82 Correct 453 ms 43036 KB Output is correct
83 Correct 445 ms 44188 KB Output is correct
84 Correct 436 ms 43500 KB Output is correct
85 Correct 464 ms 43988 KB Output is correct
86 Correct 484 ms 43472 KB Output is correct
87 Correct 475 ms 43996 KB Output is correct
88 Correct 450 ms 43596 KB Output is correct
89 Correct 599 ms 42656 KB Output is correct
90 Correct 600 ms 42676 KB Output is correct
91 Correct 611 ms 43508 KB Output is correct
92 Correct 682 ms 42744 KB Output is correct
93 Correct 607 ms 42860 KB Output is correct
94 Correct 607 ms 42908 KB Output is correct
95 Correct 597 ms 43332 KB Output is correct
96 Correct 614 ms 43140 KB Output is correct
97 Correct 614 ms 42836 KB Output is correct
98 Correct 628 ms 43076 KB Output is correct
99 Correct 615 ms 43216 KB Output is correct
100 Correct 631 ms 43108 KB Output is correct
101 Correct 573 ms 42940 KB Output is correct
102 Correct 553 ms 43028 KB Output is correct