답안 #204031

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
204031 2020-02-24T01:02:32 Z savacska Fire (JOI20_ho_t5) C++14
8 / 100
1000 ms 21088 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

const int CS = 450;

struct My_queue
{
 	deque <pair <int, int> > qu;
 	void add(int x, int pos)
 	{
 	 	while (!qu.empty() && qu.back().x <= x) qu.pop_back();
 	 	qu.push_back(mp(x, pos));
 	 	return;
 	}
 	int get_max()
 	{
 	 	return qu[0].x;
 	}
 	void pop(int pos)
 	{
 	 	if (qu[0].y == pos) qu.pop_front();
 	 	return;
 	}
};

ll summa[200005], pref[200005], answer[200005];
int mas[200005], maxim[200005];
vector <pair <int, int> > zapr[200005];

int main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
 	ios_base::sync_with_stdio(0); cin.tie(0);

 	int n, quer;
 	cin >> n >> quer;
 	for (int i = 1; i <= n; i++) cin >> mas[i];
 	for (int i = 1; i <= quer; i++)
 	{
 	 	int tim, lef, rig;
 	 	cin >> tim >> lef >> rig;
 	 	zapr[rig].pb(mp(tim, i));
 	 	zapr[lef - 1].pb(mp(tim, -i));
 	}

 	for (int i = 1; i <= (n - 1) / CS + 1; i++)
 	{
 	 	int lef = (i - 1) * CS + 1, rig = min(n, i * CS);
 	 	for (int j = 0; j <= n; j++) summa[j] = 0;

 	   	int uk = lef, tekmax = mas[lef], cur = mas[lef - 1];
 	   	for (int j = lef - 1; j >= 1; j--)
 	   	{
 	   		cur = max(cur, mas[j]);
 	   		maxim[j] = cur;
 	   		while (uk <= rig && tekmax < cur)
 	   		{
 	   			uk++;
 	   			tekmax = max(tekmax, mas[uk]);
 	   		}
 	   		summa[lef - j] += (ll) cur, summa[uk - j] -= (ll) cur;
 	   	}
 	   	for (int j = 0; j >= lef - n; j--)
 	   	{
 	   	 	summa[lef - j] += (ll) cur;
 	   	 	summa[min(uk - j, n + 1)] -= (ll) cur;
 	   	}

 	   	uk = lef - 1, tekmax = mas[lef - 1], cur = mas[lef];
 	   	for (int j = lef; j <= rig; j++)
 	   	{
 	   	 	cur = max(cur, mas[j]);
 	   	 	maxim[j] = cur;
 	   	 	while (uk > 0 && tekmax <= cur)
 	   	 	{
 	   	 		uk--;
 	   	 		tekmax = max(tekmax, mas[uk]); 	
 	   	 	}
 	   	 	if (uk == 0) summa[j - uk] += (ll) cur, summa[n + 1] -= (ll) cur;
 	   	 	summa[j - lef + 1] += (ll) cur, summa[j - uk] -= (ll) cur;
 	   	}
 	   	for (int j = 1; j <= n; j++) summa[j] += summa[j - 1];
 	   	

 	   	for (int j = lef; j <= rig; j++)
 	   	{
 	   		int mx = mas[j];
 	   		for (int z = j; z <= rig; z++)
 	   		{
 	   		 	mx = max(mx, mas[z]);
 	   		 	summa[z - j] += (ll) mx;
 	   		}
 	   	}

 	   	for (int j = lef; j <= rig; j++)
 	   	{
 	   	 	for (int z = 0; z < (int) zapr[j].size(); z++)
 	   	 	{
 	   	 	 	int tim = zapr[j][z].x, num = zapr[j][z].y;
 	   	 	 	if (num > 0) answer[num] += pref[tim];
 	   	 	 	else answer[-num] -= pref[tim];

 	   	 	 	ll ans = 0;
 	   	 	 	if (tim <= CS)
 	   	 	 	{
 	   	 	 		My_queue S;
 	   	 	 		for (int k = max(lef - tim, 1); k < lef; k++) S.add(mas[k], k);
 	   	 	 		for (int k = lef; k <= j; k++)
 	   	 	 		{
 	   	 	 	 		S.add(mas[k], k);
 	   	 	 	 		ans += (ll) S.get_max();
 	   	 	 	 		S.pop(k - tim);
 	   	 	 		}
 	   	 	 	}
 	   	 	 	else
 	   	 	 	{
 	   	 	 	 	for (int k = lef; k <= j; k++) ans += (ll) max(maxim[k], maxim[max(k - tim, 1)]);
 	   	 	 	}
 	   	 	 	if (num > 0) answer[num] += ans;
 	   	 	 	else answer[-num] -= ans;
 	   	 	}
 	   	}

 	   	for (int j = 0; j <= n; j++) pref[j] += summa[j];
 	}

 	for (int i = 1; i <= quer; i++) cout << answer[i] << '\n';
 	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 8 ms 5112 KB Output is correct
3 Correct 8 ms 5112 KB Output is correct
4 Correct 10 ms 5112 KB Output is correct
5 Correct 9 ms 5112 KB Output is correct
6 Correct 8 ms 5112 KB Output is correct
7 Correct 8 ms 5016 KB Output is correct
8 Correct 8 ms 5112 KB Output is correct
9 Correct 8 ms 5112 KB Output is correct
10 Correct 8 ms 5112 KB Output is correct
11 Correct 9 ms 5112 KB Output is correct
12 Correct 9 ms 4984 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 8 ms 5112 KB Output is correct
15 Correct 8 ms 5112 KB Output is correct
16 Correct 8 ms 5112 KB Output is correct
17 Correct 8 ms 5112 KB Output is correct
18 Correct 8 ms 5112 KB Output is correct
19 Correct 8 ms 5112 KB Output is correct
20 Correct 8 ms 5112 KB Output is correct
21 Correct 8 ms 5112 KB Output is correct
22 Correct 8 ms 5112 KB Output is correct
23 Correct 8 ms 5112 KB Output is correct
24 Correct 8 ms 5112 KB Output is correct
25 Correct 9 ms 5112 KB Output is correct
26 Correct 9 ms 5116 KB Output is correct
27 Correct 9 ms 5112 KB Output is correct
28 Correct 10 ms 5112 KB Output is correct
29 Correct 8 ms 5112 KB Output is correct
30 Correct 8 ms 5112 KB Output is correct
31 Correct 9 ms 5116 KB Output is correct
32 Correct 8 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 940 ms 20728 KB Output is correct
3 Correct 944 ms 20640 KB Output is correct
4 Correct 952 ms 20812 KB Output is correct
5 Correct 959 ms 20708 KB Output is correct
6 Correct 963 ms 20752 KB Output is correct
7 Correct 960 ms 20984 KB Output is correct
8 Correct 978 ms 20904 KB Output is correct
9 Correct 972 ms 21008 KB Output is correct
10 Correct 929 ms 20876 KB Output is correct
11 Correct 965 ms 20984 KB Output is correct
12 Correct 959 ms 20668 KB Output is correct
13 Execution timed out 1020 ms 20960 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 969 ms 20276 KB Output is correct
3 Correct 921 ms 20088 KB Output is correct
4 Correct 978 ms 20216 KB Output is correct
5 Correct 923 ms 19924 KB Output is correct
6 Correct 938 ms 19956 KB Output is correct
7 Correct 952 ms 20032 KB Output is correct
8 Correct 934 ms 20344 KB Output is correct
9 Correct 946 ms 20216 KB Output is correct
10 Correct 913 ms 19664 KB Output is correct
11 Correct 974 ms 20472 KB Output is correct
12 Correct 951 ms 19960 KB Output is correct
13 Correct 965 ms 20316 KB Output is correct
14 Correct 932 ms 19888 KB Output is correct
15 Correct 983 ms 20088 KB Output is correct
16 Correct 936 ms 19956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 985 ms 19064 KB Output is correct
2 Correct 991 ms 19064 KB Output is correct
3 Execution timed out 1064 ms 19320 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5112 KB Output is correct
2 Correct 8 ms 5112 KB Output is correct
3 Correct 8 ms 5112 KB Output is correct
4 Correct 10 ms 5112 KB Output is correct
5 Correct 9 ms 5112 KB Output is correct
6 Correct 8 ms 5112 KB Output is correct
7 Correct 8 ms 5016 KB Output is correct
8 Correct 8 ms 5112 KB Output is correct
9 Correct 8 ms 5112 KB Output is correct
10 Correct 8 ms 5112 KB Output is correct
11 Correct 9 ms 5112 KB Output is correct
12 Correct 9 ms 4984 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 8 ms 5112 KB Output is correct
15 Correct 8 ms 5112 KB Output is correct
16 Correct 8 ms 5112 KB Output is correct
17 Correct 8 ms 5112 KB Output is correct
18 Correct 8 ms 5112 KB Output is correct
19 Correct 8 ms 5112 KB Output is correct
20 Correct 8 ms 5112 KB Output is correct
21 Correct 8 ms 5112 KB Output is correct
22 Correct 8 ms 5112 KB Output is correct
23 Correct 8 ms 5112 KB Output is correct
24 Correct 8 ms 5112 KB Output is correct
25 Correct 9 ms 5112 KB Output is correct
26 Correct 9 ms 5116 KB Output is correct
27 Correct 9 ms 5112 KB Output is correct
28 Correct 10 ms 5112 KB Output is correct
29 Correct 8 ms 5112 KB Output is correct
30 Correct 8 ms 5112 KB Output is correct
31 Correct 9 ms 5116 KB Output is correct
32 Correct 8 ms 5112 KB Output is correct
33 Correct 954 ms 20772 KB Output is correct
34 Correct 973 ms 21088 KB Output is correct
35 Correct 987 ms 20696 KB Output is correct
36 Correct 962 ms 20728 KB Output is correct
37 Correct 961 ms 20600 KB Output is correct
38 Correct 985 ms 20856 KB Output is correct
39 Correct 965 ms 20872 KB Output is correct
40 Correct 939 ms 20860 KB Output is correct
41 Execution timed out 1004 ms 20860 KB Time limit exceeded
42 Halted 0 ms 0 KB -