Submission #872030

# Submission time Handle Problem Language Result Execution time Memory
872030 2023-11-12T06:48:26 Z Hyojin 역사적 조사 (JOI14_historical) C++17
100 / 100
215 ms 7240 KB
#include <bits/stdc++.h>
using namespace std;
#define bit(n,i) ((n>>i)&1) 
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define ep emplace_back
#define pii pair<int,int>
#define piii pair<int,pii> 
#define fi first
#define se second
#define ll long long
#define debug(x) cerr << #x << ' ' << x << '\n'
#define dbg(x) cerr<<#x<<' '<<x<<' '
const int base=31;
const int MOD=1e9+7;
const int N=1e5+5;
const int B=sqrt(N);
vector<int>f;
int n,q,a[N],timeDfs;
pii mp[N];
ll cur=0,pre=0;
void add(int x)
{
	if (mp[x].fi!=timeDfs)
	{
		mp[x]={timeDfs,0};
	}
	mp[x].se++;
	cur=max(cur,1ll*f[x]*mp[x].se);
}
void erase(int x)
{
	mp[x].se--;
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef Shiho
    	freopen("izumi_shiho_supremacy.in","r", stdin);
    	freopen("izumi_shiho_supremacy.out","w", stdout);
	#endif
	cin>>n>>q;
	for (int i=1;i<=n;i++) 
	{
		cin>>a[i];
		f.pb(a[i]);
	}
	sort(all(f));
	f.erase(unique(all(f)),f.end());
	for (int i=1;i<=n;i++) a[i]=lower_bound(all(f),a[i])-f.begin();	
	vector<ll>ans(q);
	vector<array<int,3>>queries(q);
	for (int i=0;i<q;i++)
	{
		int l,r;
		cin>>l>>r;
		queries[i]={l,r,i};
	}
	sort(all(queries),[&](array<int,3>x,array<int,3>y){
		if (x[0]/B!=y[0]/B) return x[0]<y[0];
		return x[1]<y[1];
	});
	int preblock=-1;
	int preR=-1;
	for (auto [l,r,id]:queries)
	{
		int idL=l/B;
		int idR=r/B;
		if (idL!=preblock)
		{
			++timeDfs;
			preblock=idL;
			pre=cur=0;
			preR=(idL+1)*B;
		}
		if (idL==idR)
		{
			pre=cur;
			for (int i=l;i<=r;i++) add(a[i]);
			ans[id]=cur;
			cur=pre;
			for (int i=l;i<=r;i++) erase(a[i]);
		}
		else 
		{
			for (;preR<=r;preR++) add(a[preR]);
			pre=cur;
			for (int i=l;i<=(idL+1)*B-1;i++) add(a[i]);
			ans[id]=cur;
			cur=pre;
			for (int i=l;i<=(idL+1)*B-1;i++) erase(a[i]);
		}
	}
	for (int i=0;i<q;i++) cout<<ans[i]<<"\n";
	return 0;	
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 464 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 464 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 508 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 4 ms 408 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 5 ms 716 KB Output is correct
23 Correct 5 ms 604 KB Output is correct
24 Correct 5 ms 712 KB Output is correct
25 Correct 5 ms 604 KB Output is correct
26 Correct 6 ms 856 KB Output is correct
27 Correct 6 ms 604 KB Output is correct
28 Correct 6 ms 744 KB Output is correct
29 Correct 6 ms 604 KB Output is correct
30 Correct 6 ms 604 KB Output is correct
31 Correct 5 ms 604 KB Output is correct
32 Correct 5 ms 604 KB Output is correct
33 Correct 6 ms 604 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 6 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 544 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 524 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 6 ms 984 KB Output is correct
10 Correct 5 ms 1248 KB Output is correct
11 Correct 56 ms 4992 KB Output is correct
12 Correct 17 ms 2016 KB Output is correct
13 Correct 36 ms 2804 KB Output is correct
14 Correct 59 ms 4564 KB Output is correct
15 Correct 55 ms 7240 KB Output is correct
16 Correct 96 ms 5184 KB Output is correct
17 Correct 55 ms 2460 KB Output is correct
18 Correct 89 ms 5172 KB Output is correct
19 Correct 94 ms 6244 KB Output is correct
20 Correct 45 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 464 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 508 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 4 ms 408 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 5 ms 716 KB Output is correct
23 Correct 5 ms 604 KB Output is correct
24 Correct 5 ms 712 KB Output is correct
25 Correct 5 ms 604 KB Output is correct
26 Correct 6 ms 856 KB Output is correct
27 Correct 6 ms 604 KB Output is correct
28 Correct 6 ms 744 KB Output is correct
29 Correct 6 ms 604 KB Output is correct
30 Correct 6 ms 604 KB Output is correct
31 Correct 5 ms 604 KB Output is correct
32 Correct 5 ms 604 KB Output is correct
33 Correct 6 ms 604 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 6 ms 604 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 544 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 524 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 3 ms 604 KB Output is correct
44 Correct 6 ms 984 KB Output is correct
45 Correct 5 ms 1248 KB Output is correct
46 Correct 56 ms 4992 KB Output is correct
47 Correct 17 ms 2016 KB Output is correct
48 Correct 36 ms 2804 KB Output is correct
49 Correct 59 ms 4564 KB Output is correct
50 Correct 55 ms 7240 KB Output is correct
51 Correct 96 ms 5184 KB Output is correct
52 Correct 55 ms 2460 KB Output is correct
53 Correct 89 ms 5172 KB Output is correct
54 Correct 94 ms 6244 KB Output is correct
55 Correct 45 ms 3540 KB Output is correct
56 Correct 10 ms 860 KB Output is correct
57 Correct 22 ms 1624 KB Output is correct
58 Correct 38 ms 2132 KB Output is correct
59 Correct 56 ms 2896 KB Output is correct
60 Correct 75 ms 3288 KB Output is correct
61 Correct 85 ms 4124 KB Output is correct
62 Correct 96 ms 4724 KB Output is correct
63 Correct 117 ms 5328 KB Output is correct
64 Correct 130 ms 6100 KB Output is correct
65 Correct 169 ms 6100 KB Output is correct
66 Correct 147 ms 6196 KB Output is correct
67 Correct 150 ms 6132 KB Output is correct
68 Correct 164 ms 6380 KB Output is correct
69 Correct 204 ms 6732 KB Output is correct
70 Correct 208 ms 6868 KB Output is correct
71 Correct 210 ms 6876 KB Output is correct
72 Correct 215 ms 6864 KB Output is correct
73 Correct 207 ms 6760 KB Output is correct
74 Correct 204 ms 6612 KB Output is correct
75 Correct 200 ms 6720 KB Output is correct
76 Correct 195 ms 6736 KB Output is correct
77 Correct 203 ms 6828 KB Output is correct
78 Correct 193 ms 6652 KB Output is correct
79 Correct 191 ms 6664 KB Output is correct
80 Correct 171 ms 6748 KB Output is correct