Submission #201229

# Submission time Handle Problem Language Result Execution time Memory
201229 2020-02-10T00:03:56 Z ainta Fire (JOI20_ho_t5) C++17
100 / 100
499 ms 28920 KB
#include<cstdio>
#include<algorithm>
#define N_ 201000
#define SZ 262144
using namespace std;
int n, Q, st[N_], w[N_], cnt;
int Right[N_], Left[N_];
struct point {
	int ck, x, y, c;
	bool operator < (const point &p)const {
		return x - y < p.x - p.y;
	}
}U[N_*10];
long long Res[N_];
void Add(int x, int y, int c) {
	U[cnt++] = { 0,x,y,c };
}
struct AA {
	long long BIT[N_];
	void init() {
		for (int i = 0; i < N_; i++)BIT[i] = 0;
	}
	void Add(int a, long long b) {
		while (a < N_) {
			BIT[a] += b;
			a += (a&-a);
		}
	}
	long long Sum(int a) {
		long long r = 0;
		while (a) {
			r += BIT[a];
			a -= (a&-a);
		}
		return r;
	}
}B1, B2;
void Add2(int x, long long c) {
	B1.Add(x, c);
	B2.Add(x, c*(-x + 1));
}
long long Calc(int x) {
	return B1.Sum(x) * x + B2.Sum(x);
}
int main() {
	int i;
	scanf("%d%d", &n, &Q);
	int top = 0;
	for (i = 1; i <= n+1; i++) {
		if(i!=n+1)scanf("%d", &w[i]);
		while (top && (i==n+1 || w[st[top]] < w[i])) {
			Right[st[top]] = i;
			top--;
		}
		Left[i] = st[top];
		st[++top] = i;
	}
	for (i = 1; i <= n; i++) {
		Add(1, i, w[i]);
		if (Left[i] != 0) {
			Add(i - Left[i] + 1, i, -w[i]);
		}
		if (Right[i] != n+1) {
			Add(Right[i] - i + 1, Right[i], -w[i]);
		}
		if (Left[i] != 0 && Right[i] != n+1) {
			Add(Right[i] - Left[i] + 1, Right[i], w[i]);
		}
	}
	for (i = 1; i <= Q; i++) {
		int t, b, e;
		scanf("%d%d%d", &t, &b, &e);
		t++;
		U[cnt++] = { 1,t,e,i };
		U[cnt++] = { 1,t,b-1,-i };
	}
	sort(U, U + cnt);
	for (i = 0; i < cnt; i++) {
		if (U[i].ck == 0) {
			Add2(U[i].y, U[i].c);
		}
		else {
			long long t = Calc(U[i].y);
			if (U[i].c < 0)Res[-U[i].c] -= t;
			else Res[U[i].c] += t;
		}
	}
	B1.init();
	B2.init();
	for (i = cnt - 1; i >= 0; i--) {
		if (U[i].ck == 0) {
			Add2(U[i].x, U[i].c);
		}
		else {
			long long t = Calc(U[i].x);
			if (U[i].c < 0)Res[-U[i].c] -= t;
			else Res[U[i].c] += t;
		}
	}
	for (i = 1; i <= Q; i++)printf("%lld\n", Res[i]);
}

Compilation message

ho_t5.cpp: In function 'int main()':
ho_t5.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &Q);
  ~~~~~^~~~~~~~~~~~~~~~
ho_t5.cpp:50:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   if(i!=n+1)scanf("%d", &w[i]);
             ~~~~~^~~~~~~~~~~~~
ho_t5.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &t, &b, &e);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3448 KB Output is correct
2 Correct 6 ms 3576 KB Output is correct
3 Correct 7 ms 3448 KB Output is correct
4 Correct 7 ms 3452 KB Output is correct
5 Correct 7 ms 3576 KB Output is correct
6 Correct 7 ms 3576 KB Output is correct
7 Correct 7 ms 3576 KB Output is correct
8 Correct 7 ms 3448 KB Output is correct
9 Correct 6 ms 3576 KB Output is correct
10 Correct 6 ms 3576 KB Output is correct
11 Correct 7 ms 3448 KB Output is correct
12 Correct 7 ms 3448 KB Output is correct
13 Correct 7 ms 3576 KB Output is correct
14 Correct 7 ms 3576 KB Output is correct
15 Correct 7 ms 3448 KB Output is correct
16 Correct 7 ms 3448 KB Output is correct
17 Correct 7 ms 3448 KB Output is correct
18 Correct 7 ms 3448 KB Output is correct
19 Correct 7 ms 3448 KB Output is correct
20 Correct 7 ms 3576 KB Output is correct
21 Correct 7 ms 3444 KB Output is correct
22 Correct 6 ms 3448 KB Output is correct
23 Correct 7 ms 3448 KB Output is correct
24 Correct 6 ms 3448 KB Output is correct
25 Correct 6 ms 3448 KB Output is correct
26 Correct 6 ms 3448 KB Output is correct
27 Correct 7 ms 3448 KB Output is correct
28 Correct 6 ms 3448 KB Output is correct
29 Correct 7 ms 3576 KB Output is correct
30 Correct 6 ms 3448 KB Output is correct
31 Correct 6 ms 3448 KB Output is correct
32 Correct 7 ms 3452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3448 KB Output is correct
2 Correct 361 ms 28408 KB Output is correct
3 Correct 338 ms 28408 KB Output is correct
4 Correct 359 ms 28664 KB Output is correct
5 Correct 361 ms 28664 KB Output is correct
6 Correct 366 ms 28552 KB Output is correct
7 Correct 364 ms 28920 KB Output is correct
8 Correct 369 ms 28872 KB Output is correct
9 Correct 368 ms 28920 KB Output is correct
10 Correct 358 ms 28280 KB Output is correct
11 Correct 362 ms 28920 KB Output is correct
12 Correct 336 ms 28152 KB Output is correct
13 Correct 379 ms 28664 KB Output is correct
14 Correct 356 ms 28408 KB Output is correct
15 Correct 366 ms 28536 KB Output is correct
16 Correct 357 ms 28536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3448 KB Output is correct
2 Correct 369 ms 27768 KB Output is correct
3 Correct 386 ms 27256 KB Output is correct
4 Correct 374 ms 28024 KB Output is correct
5 Correct 391 ms 27256 KB Output is correct
6 Correct 376 ms 27768 KB Output is correct
7 Correct 381 ms 27640 KB Output is correct
8 Correct 384 ms 27768 KB Output is correct
9 Correct 356 ms 27384 KB Output is correct
10 Correct 375 ms 27128 KB Output is correct
11 Correct 374 ms 28024 KB Output is correct
12 Correct 401 ms 27640 KB Output is correct
13 Correct 385 ms 28152 KB Output is correct
14 Correct 367 ms 27384 KB Output is correct
15 Correct 379 ms 27768 KB Output is correct
16 Correct 368 ms 27640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 328 ms 23968 KB Output is correct
2 Correct 337 ms 24112 KB Output is correct
3 Correct 358 ms 24472 KB Output is correct
4 Correct 369 ms 24032 KB Output is correct
5 Correct 373 ms 24032 KB Output is correct
6 Correct 345 ms 23928 KB Output is correct
7 Correct 375 ms 24292 KB Output is correct
8 Correct 345 ms 24248 KB Output is correct
9 Correct 338 ms 24060 KB Output is correct
10 Correct 350 ms 24100 KB Output is correct
11 Correct 357 ms 24172 KB Output is correct
12 Correct 349 ms 24236 KB Output is correct
13 Correct 348 ms 24144 KB Output is correct
14 Correct 341 ms 24160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3448 KB Output is correct
2 Correct 6 ms 3576 KB Output is correct
3 Correct 7 ms 3448 KB Output is correct
4 Correct 7 ms 3452 KB Output is correct
5 Correct 7 ms 3576 KB Output is correct
6 Correct 7 ms 3576 KB Output is correct
7 Correct 7 ms 3576 KB Output is correct
8 Correct 7 ms 3448 KB Output is correct
9 Correct 6 ms 3576 KB Output is correct
10 Correct 6 ms 3576 KB Output is correct
11 Correct 7 ms 3448 KB Output is correct
12 Correct 7 ms 3448 KB Output is correct
13 Correct 7 ms 3576 KB Output is correct
14 Correct 7 ms 3576 KB Output is correct
15 Correct 7 ms 3448 KB Output is correct
16 Correct 7 ms 3448 KB Output is correct
17 Correct 7 ms 3448 KB Output is correct
18 Correct 7 ms 3448 KB Output is correct
19 Correct 7 ms 3448 KB Output is correct
20 Correct 7 ms 3576 KB Output is correct
21 Correct 7 ms 3444 KB Output is correct
22 Correct 6 ms 3448 KB Output is correct
23 Correct 7 ms 3448 KB Output is correct
24 Correct 6 ms 3448 KB Output is correct
25 Correct 6 ms 3448 KB Output is correct
26 Correct 6 ms 3448 KB Output is correct
27 Correct 7 ms 3448 KB Output is correct
28 Correct 6 ms 3448 KB Output is correct
29 Correct 7 ms 3576 KB Output is correct
30 Correct 6 ms 3448 KB Output is correct
31 Correct 6 ms 3448 KB Output is correct
32 Correct 7 ms 3452 KB Output is correct
33 Correct 422 ms 28364 KB Output is correct
34 Correct 414 ms 28896 KB Output is correct
35 Correct 429 ms 28664 KB Output is correct
36 Correct 398 ms 28412 KB Output is correct
37 Correct 399 ms 28260 KB Output is correct
38 Correct 409 ms 28504 KB Output is correct
39 Correct 419 ms 28512 KB Output is correct
40 Correct 383 ms 28404 KB Output is correct
41 Correct 414 ms 28624 KB Output is correct
42 Correct 499 ms 28640 KB Output is correct
43 Correct 349 ms 28792 KB Output is correct
44 Correct 360 ms 28884 KB Output is correct
45 Correct 366 ms 28152 KB Output is correct
46 Correct 352 ms 28664 KB Output is correct
47 Correct 363 ms 28256 KB Output is correct
48 Correct 351 ms 28024 KB Output is correct
49 Correct 356 ms 28440 KB Output is correct
50 Correct 358 ms 28920 KB Output is correct
51 Correct 363 ms 28792 KB Output is correct
52 Correct 365 ms 28536 KB Output is correct
53 Correct 349 ms 28536 KB Output is correct
54 Correct 384 ms 28280 KB Output is correct
55 Correct 375 ms 28280 KB Output is correct
56 Correct 372 ms 28792 KB Output is correct
57 Correct 395 ms 28284 KB Output is correct
58 Correct 392 ms 28824 KB Output is correct
59 Correct 361 ms 28408 KB Output is correct
60 Correct 338 ms 28408 KB Output is correct
61 Correct 359 ms 28664 KB Output is correct
62 Correct 361 ms 28664 KB Output is correct
63 Correct 366 ms 28552 KB Output is correct
64 Correct 364 ms 28920 KB Output is correct
65 Correct 369 ms 28872 KB Output is correct
66 Correct 368 ms 28920 KB Output is correct
67 Correct 358 ms 28280 KB Output is correct
68 Correct 362 ms 28920 KB Output is correct
69 Correct 336 ms 28152 KB Output is correct
70 Correct 379 ms 28664 KB Output is correct
71 Correct 356 ms 28408 KB Output is correct
72 Correct 366 ms 28536 KB Output is correct
73 Correct 357 ms 28536 KB Output is correct
74 Correct 369 ms 27768 KB Output is correct
75 Correct 386 ms 27256 KB Output is correct
76 Correct 374 ms 28024 KB Output is correct
77 Correct 391 ms 27256 KB Output is correct
78 Correct 376 ms 27768 KB Output is correct
79 Correct 381 ms 27640 KB Output is correct
80 Correct 384 ms 27768 KB Output is correct
81 Correct 356 ms 27384 KB Output is correct
82 Correct 375 ms 27128 KB Output is correct
83 Correct 374 ms 28024 KB Output is correct
84 Correct 401 ms 27640 KB Output is correct
85 Correct 385 ms 28152 KB Output is correct
86 Correct 367 ms 27384 KB Output is correct
87 Correct 379 ms 27768 KB Output is correct
88 Correct 368 ms 27640 KB Output is correct
89 Correct 328 ms 23968 KB Output is correct
90 Correct 337 ms 24112 KB Output is correct
91 Correct 358 ms 24472 KB Output is correct
92 Correct 369 ms 24032 KB Output is correct
93 Correct 373 ms 24032 KB Output is correct
94 Correct 345 ms 23928 KB Output is correct
95 Correct 375 ms 24292 KB Output is correct
96 Correct 345 ms 24248 KB Output is correct
97 Correct 338 ms 24060 KB Output is correct
98 Correct 350 ms 24100 KB Output is correct
99 Correct 357 ms 24172 KB Output is correct
100 Correct 349 ms 24236 KB Output is correct
101 Correct 348 ms 24144 KB Output is correct
102 Correct 341 ms 24160 KB Output is correct