답안 #201858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201858 2020-02-12T09:48:34 Z MvC Fire (JOI20_ho_t5) C++14
14 / 100
1000 ms 28524 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int n,q,i,lf[nmax],rg[nmax],x,r[nmax],j,v[nmax];
ll a[nmax],b[nmax],fw[nmax],rs[nmax];
vector<int>vc[nmax],ad,dl[nmax],nw;
stack<int>st;
void upd(int i,ll vl)
{
	for(;i<=n;i+=i&(-i))fw[i]+=vl;
}
ll qry(int i)
{
	ll rs=0;
	for(;i>=1;i-=i&(-i))rs+=fw[i];
	return rs;
}
ll qry(int l,int r)
{
	ll rs=qry(r);
	if(l>1)rs-=qry(l-1);
	return rs;
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>q;
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<=q;i++)
	{
		cin>>x>>lf[i]>>rg[i];
		vc[x].pb(i);
	}
	/*for(i=1;i<=n;i++)
	{
		while(!st.empty() && a[st.top()]<=a[i])st.pop();
		if(st.empty())l[i]=1;
		else l[i]=st.top()+1;
		st.push(i);
	}
	while(!st.empty())st.pop();*/
	for(i=n;i>=1;i--)
	{
		while(!st.empty() && a[st.top()]<=a[i])st.pop();
		if(st.empty())r[i]=n;
		else r[i]=st.top()-1;
		st.push(i);
	}
	for(i=1;i<=n;i++)
	{
		b[i]=a[i];
		upd(i,a[i]);
		ad.pb(i);
		v[i]=1;
		dl[r[i]-i+1].pb(i);
	}
	for(i=1;i<=n;i++)
	{
		for(j=0;j<(int)dl[i].size();j++)v[dl[i][j]]=0;
		nw.clear();
		for(j=0;j<(int)ad.size();j++)if(v[ad[j]])nw.pb(ad[j]);
		ad=nw;
		for(j=0;j<(int)ad.size();j++)
		{
			upd(ad[j]+i,-b[ad[j]+i]);
			b[ad[j]+i]=a[ad[j]];
			upd(ad[j]+i,b[ad[j]+i]);
		}
		for(j=0;j<(int)vc[i].size();j++)
		{
			rs[vc[i][j]]=qry(lf[vc[i][j]],rg[vc[i][j]]);
		}
	}
	for(i=1;i<=q;i++)cout<<rs[i]<<'\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9720 KB Output is correct
2 Correct 12 ms 9848 KB Output is correct
3 Correct 12 ms 9848 KB Output is correct
4 Correct 12 ms 9824 KB Output is correct
5 Correct 12 ms 9848 KB Output is correct
6 Correct 11 ms 9848 KB Output is correct
7 Correct 13 ms 9848 KB Output is correct
8 Correct 13 ms 9848 KB Output is correct
9 Correct 12 ms 9848 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 12 ms 9848 KB Output is correct
12 Correct 12 ms 9848 KB Output is correct
13 Correct 11 ms 9848 KB Output is correct
14 Correct 11 ms 9848 KB Output is correct
15 Correct 13 ms 9848 KB Output is correct
16 Correct 12 ms 9848 KB Output is correct
17 Correct 11 ms 9848 KB Output is correct
18 Correct 11 ms 9848 KB Output is correct
19 Correct 12 ms 9848 KB Output is correct
20 Correct 12 ms 9848 KB Output is correct
21 Correct 11 ms 9848 KB Output is correct
22 Correct 11 ms 9848 KB Output is correct
23 Correct 12 ms 9848 KB Output is correct
24 Correct 13 ms 9852 KB Output is correct
25 Correct 12 ms 9848 KB Output is correct
26 Correct 12 ms 9848 KB Output is correct
27 Correct 12 ms 9848 KB Output is correct
28 Correct 11 ms 9848 KB Output is correct
29 Correct 12 ms 9848 KB Output is correct
30 Correct 12 ms 9848 KB Output is correct
31 Correct 12 ms 9720 KB Output is correct
32 Correct 12 ms 9976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9720 KB Output is correct
2 Correct 260 ms 25712 KB Output is correct
3 Correct 246 ms 25452 KB Output is correct
4 Correct 244 ms 25456 KB Output is correct
5 Correct 248 ms 25428 KB Output is correct
6 Correct 251 ms 25456 KB Output is correct
7 Correct 252 ms 25608 KB Output is correct
8 Correct 277 ms 25840 KB Output is correct
9 Correct 252 ms 25864 KB Output is correct
10 Correct 265 ms 25452 KB Output is correct
11 Correct 262 ms 25964 KB Output is correct
12 Correct 277 ms 25472 KB Output is correct
13 Correct 248 ms 25584 KB Output is correct
14 Correct 270 ms 25452 KB Output is correct
15 Correct 262 ms 25456 KB Output is correct
16 Correct 266 ms 25708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9720 KB Output is correct
2 Correct 330 ms 27408 KB Output is correct
3 Correct 336 ms 27240 KB Output is correct
4 Correct 367 ms 27844 KB Output is correct
5 Correct 313 ms 27488 KB Output is correct
6 Correct 328 ms 27368 KB Output is correct
7 Correct 334 ms 27360 KB Output is correct
8 Correct 321 ms 27496 KB Output is correct
9 Correct 319 ms 27356 KB Output is correct
10 Correct 310 ms 26972 KB Output is correct
11 Correct 345 ms 27696 KB Output is correct
12 Correct 334 ms 27500 KB Output is correct
13 Correct 344 ms 27836 KB Output is correct
14 Correct 307 ms 27244 KB Output is correct
15 Correct 374 ms 27764 KB Output is correct
16 Correct 327 ms 27432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 27024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9720 KB Output is correct
2 Correct 12 ms 9848 KB Output is correct
3 Correct 12 ms 9848 KB Output is correct
4 Correct 12 ms 9824 KB Output is correct
5 Correct 12 ms 9848 KB Output is correct
6 Correct 11 ms 9848 KB Output is correct
7 Correct 13 ms 9848 KB Output is correct
8 Correct 13 ms 9848 KB Output is correct
9 Correct 12 ms 9848 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 12 ms 9848 KB Output is correct
12 Correct 12 ms 9848 KB Output is correct
13 Correct 11 ms 9848 KB Output is correct
14 Correct 11 ms 9848 KB Output is correct
15 Correct 13 ms 9848 KB Output is correct
16 Correct 12 ms 9848 KB Output is correct
17 Correct 11 ms 9848 KB Output is correct
18 Correct 11 ms 9848 KB Output is correct
19 Correct 12 ms 9848 KB Output is correct
20 Correct 12 ms 9848 KB Output is correct
21 Correct 11 ms 9848 KB Output is correct
22 Correct 11 ms 9848 KB Output is correct
23 Correct 12 ms 9848 KB Output is correct
24 Correct 13 ms 9852 KB Output is correct
25 Correct 12 ms 9848 KB Output is correct
26 Correct 12 ms 9848 KB Output is correct
27 Correct 12 ms 9848 KB Output is correct
28 Correct 11 ms 9848 KB Output is correct
29 Correct 12 ms 9848 KB Output is correct
30 Correct 12 ms 9848 KB Output is correct
31 Correct 12 ms 9720 KB Output is correct
32 Correct 12 ms 9976 KB Output is correct
33 Correct 334 ms 28260 KB Output is correct
34 Correct 355 ms 28500 KB Output is correct
35 Correct 332 ms 28400 KB Output is correct
36 Correct 345 ms 28252 KB Output is correct
37 Correct 360 ms 28260 KB Output is correct
38 Correct 352 ms 28364 KB Output is correct
39 Correct 350 ms 28524 KB Output is correct
40 Correct 327 ms 28264 KB Output is correct
41 Correct 365 ms 28460 KB Output is correct
42 Correct 347 ms 28404 KB Output is correct
43 Correct 318 ms 26320 KB Output is correct
44 Correct 289 ms 26356 KB Output is correct
45 Correct 271 ms 25684 KB Output is correct
46 Correct 290 ms 26060 KB Output is correct
47 Correct 292 ms 25840 KB Output is correct
48 Correct 291 ms 25684 KB Output is correct
49 Correct 285 ms 25960 KB Output is correct
50 Correct 284 ms 26204 KB Output is correct
51 Correct 277 ms 26220 KB Output is correct
52 Correct 285 ms 26072 KB Output is correct
53 Correct 284 ms 25940 KB Output is correct
54 Correct 291 ms 25832 KB Output is correct
55 Correct 285 ms 25928 KB Output is correct
56 Correct 301 ms 26064 KB Output is correct
57 Correct 279 ms 25964 KB Output is correct
58 Correct 296 ms 26196 KB Output is correct
59 Correct 260 ms 25712 KB Output is correct
60 Correct 246 ms 25452 KB Output is correct
61 Correct 244 ms 25456 KB Output is correct
62 Correct 248 ms 25428 KB Output is correct
63 Correct 251 ms 25456 KB Output is correct
64 Correct 252 ms 25608 KB Output is correct
65 Correct 277 ms 25840 KB Output is correct
66 Correct 252 ms 25864 KB Output is correct
67 Correct 265 ms 25452 KB Output is correct
68 Correct 262 ms 25964 KB Output is correct
69 Correct 277 ms 25472 KB Output is correct
70 Correct 248 ms 25584 KB Output is correct
71 Correct 270 ms 25452 KB Output is correct
72 Correct 262 ms 25456 KB Output is correct
73 Correct 266 ms 25708 KB Output is correct
74 Correct 330 ms 27408 KB Output is correct
75 Correct 336 ms 27240 KB Output is correct
76 Correct 367 ms 27844 KB Output is correct
77 Correct 313 ms 27488 KB Output is correct
78 Correct 328 ms 27368 KB Output is correct
79 Correct 334 ms 27360 KB Output is correct
80 Correct 321 ms 27496 KB Output is correct
81 Correct 319 ms 27356 KB Output is correct
82 Correct 310 ms 26972 KB Output is correct
83 Correct 345 ms 27696 KB Output is correct
84 Correct 334 ms 27500 KB Output is correct
85 Correct 344 ms 27836 KB Output is correct
86 Correct 307 ms 27244 KB Output is correct
87 Correct 374 ms 27764 KB Output is correct
88 Correct 327 ms 27432 KB Output is correct
89 Execution timed out 1094 ms 27024 KB Time limit exceeded
90 Halted 0 ms 0 KB -