답안 #234486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234486 2020-05-24T10:02:19 Z CallMeLater Fire (JOI20_ho_t5) C++17
100 / 100
427 ms 34808 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 {
		if (x - y == p.x - p.y)
			return ck > p.ck;			
		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:49: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:52: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:74: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);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3456 KB Output is correct
2 Correct 6 ms 3456 KB Output is correct
3 Correct 7 ms 3584 KB Output is correct
4 Correct 6 ms 3456 KB Output is correct
5 Correct 6 ms 3584 KB Output is correct
6 Correct 6 ms 3456 KB Output is correct
7 Correct 6 ms 3456 KB Output is correct
8 Correct 7 ms 3712 KB Output is correct
9 Correct 6 ms 3456 KB Output is correct
10 Correct 6 ms 3456 KB Output is correct
11 Correct 6 ms 3456 KB Output is correct
12 Correct 7 ms 3456 KB Output is correct
13 Correct 6 ms 3456 KB Output is correct
14 Correct 6 ms 3456 KB Output is correct
15 Correct 6 ms 3456 KB Output is correct
16 Correct 6 ms 3712 KB Output is correct
17 Correct 6 ms 3456 KB Output is correct
18 Correct 6 ms 3456 KB Output is correct
19 Correct 6 ms 3456 KB Output is correct
20 Correct 6 ms 3456 KB Output is correct
21 Correct 7 ms 3456 KB Output is correct
22 Correct 6 ms 3584 KB Output is correct
23 Correct 6 ms 3456 KB Output is correct
24 Correct 7 ms 3456 KB Output is correct
25 Correct 6 ms 3456 KB Output is correct
26 Correct 6 ms 3456 KB Output is correct
27 Correct 7 ms 3584 KB Output is correct
28 Correct 6 ms 3584 KB Output is correct
29 Correct 6 ms 3456 KB Output is correct
30 Correct 7 ms 3456 KB Output is correct
31 Correct 6 ms 3456 KB Output is correct
32 Correct 7 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3456 KB Output is correct
2 Correct 361 ms 34224 KB Output is correct
3 Correct 343 ms 34016 KB Output is correct
4 Correct 379 ms 34236 KB Output is correct
5 Correct 368 ms 34424 KB Output is correct
6 Correct 372 ms 33912 KB Output is correct
7 Correct 368 ms 34680 KB Output is correct
8 Correct 379 ms 34424 KB Output is correct
9 Correct 372 ms 34552 KB Output is correct
10 Correct 362 ms 33912 KB Output is correct
11 Correct 360 ms 34680 KB Output is correct
12 Correct 355 ms 33784 KB Output is correct
13 Correct 394 ms 34144 KB Output is correct
14 Correct 364 ms 34020 KB Output is correct
15 Correct 383 ms 34168 KB Output is correct
16 Correct 369 ms 34168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3456 KB Output is correct
2 Correct 379 ms 33400 KB Output is correct
3 Correct 371 ms 32856 KB Output is correct
4 Correct 384 ms 33784 KB Output is correct
5 Correct 380 ms 32760 KB Output is correct
6 Correct 380 ms 33144 KB Output is correct
7 Correct 374 ms 33144 KB Output is correct
8 Correct 382 ms 33272 KB Output is correct
9 Correct 375 ms 33016 KB Output is correct
10 Correct 371 ms 32632 KB Output is correct
11 Correct 380 ms 33656 KB Output is correct
12 Correct 382 ms 33116 KB Output is correct
13 Correct 390 ms 33528 KB Output is correct
14 Correct 376 ms 32888 KB Output is correct
15 Correct 380 ms 33400 KB Output is correct
16 Correct 386 ms 33144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 317 ms 28280 KB Output is correct
2 Correct 324 ms 28068 KB Output is correct
3 Correct 325 ms 28732 KB Output is correct
4 Correct 335 ms 28280 KB Output is correct
5 Correct 354 ms 28348 KB Output is correct
6 Correct 323 ms 28024 KB Output is correct
7 Correct 334 ms 28280 KB Output is correct
8 Correct 344 ms 28412 KB Output is correct
9 Correct 336 ms 28280 KB Output is correct
10 Correct 330 ms 28152 KB Output is correct
11 Correct 345 ms 28424 KB Output is correct
12 Correct 328 ms 28540 KB Output is correct
13 Correct 325 ms 28280 KB Output is correct
14 Correct 333 ms 28408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3456 KB Output is correct
2 Correct 6 ms 3456 KB Output is correct
3 Correct 7 ms 3584 KB Output is correct
4 Correct 6 ms 3456 KB Output is correct
5 Correct 6 ms 3584 KB Output is correct
6 Correct 6 ms 3456 KB Output is correct
7 Correct 6 ms 3456 KB Output is correct
8 Correct 7 ms 3712 KB Output is correct
9 Correct 6 ms 3456 KB Output is correct
10 Correct 6 ms 3456 KB Output is correct
11 Correct 6 ms 3456 KB Output is correct
12 Correct 7 ms 3456 KB Output is correct
13 Correct 6 ms 3456 KB Output is correct
14 Correct 6 ms 3456 KB Output is correct
15 Correct 6 ms 3456 KB Output is correct
16 Correct 6 ms 3712 KB Output is correct
17 Correct 6 ms 3456 KB Output is correct
18 Correct 6 ms 3456 KB Output is correct
19 Correct 6 ms 3456 KB Output is correct
20 Correct 6 ms 3456 KB Output is correct
21 Correct 7 ms 3456 KB Output is correct
22 Correct 6 ms 3584 KB Output is correct
23 Correct 6 ms 3456 KB Output is correct
24 Correct 7 ms 3456 KB Output is correct
25 Correct 6 ms 3456 KB Output is correct
26 Correct 6 ms 3456 KB Output is correct
27 Correct 7 ms 3584 KB Output is correct
28 Correct 6 ms 3584 KB Output is correct
29 Correct 6 ms 3456 KB Output is correct
30 Correct 7 ms 3456 KB Output is correct
31 Correct 6 ms 3456 KB Output is correct
32 Correct 7 ms 3456 KB Output is correct
33 Correct 407 ms 34168 KB Output is correct
34 Correct 406 ms 34552 KB Output is correct
35 Correct 384 ms 34424 KB Output is correct
36 Correct 392 ms 34052 KB Output is correct
37 Correct 383 ms 34040 KB Output is correct
38 Correct 390 ms 34316 KB Output is correct
39 Correct 398 ms 34080 KB Output is correct
40 Correct 383 ms 33956 KB Output is correct
41 Correct 390 ms 34296 KB Output is correct
42 Correct 402 ms 34124 KB Output is correct
43 Correct 383 ms 34680 KB Output is correct
44 Correct 364 ms 34424 KB Output is correct
45 Correct 365 ms 34040 KB Output is correct
46 Correct 367 ms 34296 KB Output is correct
47 Correct 375 ms 33912 KB Output is correct
48 Correct 358 ms 33784 KB Output is correct
49 Correct 353 ms 34116 KB Output is correct
50 Correct 373 ms 34808 KB Output is correct
51 Correct 369 ms 34680 KB Output is correct
52 Correct 375 ms 34204 KB Output is correct
53 Correct 365 ms 34308 KB Output is correct
54 Correct 387 ms 33528 KB Output is correct
55 Correct 398 ms 33784 KB Output is correct
56 Correct 404 ms 34044 KB Output is correct
57 Correct 427 ms 33868 KB Output is correct
58 Correct 409 ms 34296 KB Output is correct
59 Correct 361 ms 34224 KB Output is correct
60 Correct 343 ms 34016 KB Output is correct
61 Correct 379 ms 34236 KB Output is correct
62 Correct 368 ms 34424 KB Output is correct
63 Correct 372 ms 33912 KB Output is correct
64 Correct 368 ms 34680 KB Output is correct
65 Correct 379 ms 34424 KB Output is correct
66 Correct 372 ms 34552 KB Output is correct
67 Correct 362 ms 33912 KB Output is correct
68 Correct 360 ms 34680 KB Output is correct
69 Correct 355 ms 33784 KB Output is correct
70 Correct 394 ms 34144 KB Output is correct
71 Correct 364 ms 34020 KB Output is correct
72 Correct 383 ms 34168 KB Output is correct
73 Correct 369 ms 34168 KB Output is correct
74 Correct 379 ms 33400 KB Output is correct
75 Correct 371 ms 32856 KB Output is correct
76 Correct 384 ms 33784 KB Output is correct
77 Correct 380 ms 32760 KB Output is correct
78 Correct 380 ms 33144 KB Output is correct
79 Correct 374 ms 33144 KB Output is correct
80 Correct 382 ms 33272 KB Output is correct
81 Correct 375 ms 33016 KB Output is correct
82 Correct 371 ms 32632 KB Output is correct
83 Correct 380 ms 33656 KB Output is correct
84 Correct 382 ms 33116 KB Output is correct
85 Correct 390 ms 33528 KB Output is correct
86 Correct 376 ms 32888 KB Output is correct
87 Correct 380 ms 33400 KB Output is correct
88 Correct 386 ms 33144 KB Output is correct
89 Correct 317 ms 28280 KB Output is correct
90 Correct 324 ms 28068 KB Output is correct
91 Correct 325 ms 28732 KB Output is correct
92 Correct 335 ms 28280 KB Output is correct
93 Correct 354 ms 28348 KB Output is correct
94 Correct 323 ms 28024 KB Output is correct
95 Correct 334 ms 28280 KB Output is correct
96 Correct 344 ms 28412 KB Output is correct
97 Correct 336 ms 28280 KB Output is correct
98 Correct 330 ms 28152 KB Output is correct
99 Correct 345 ms 28424 KB Output is correct
100 Correct 328 ms 28540 KB Output is correct
101 Correct 325 ms 28280 KB Output is correct
102 Correct 333 ms 28408 KB Output is correct