답안 #294550

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
294550 2020-09-09T04:27:20 Z nandonathaniel Fuel Station (NOI20_fuelstation) C++14
100 / 100
949 ms 40148 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
const LL MAXN=3e5+5,INF=1e18;

struct pom{
	LL x,a,b;
};

pom arr[MAXN];
LL tree[4*MAXN],lazy[4*MAXN],nxt[MAXN];

bool cmp(pom p,pom q){
	return p.x<q.x;
}

void updatenode(LL now,LL L,LL R,LL val){
	tree[now]+=val;
	lazy[now]+=val;
}

void pushdown(LL now,LL L,LL R){
	LL mid=(L+R)/2;
	updatenode(2*now,L,mid,lazy[now]);
	updatenode(2*now+1,mid+1,R,lazy[now]);
	lazy[now]=0;
}

LL query(LL now,LL L,LL R,LL x,LL y){
	if(L>=x && R<=y)return tree[now];
	if(L>y || R<x)return INF;
	pushdown(now,L,R);
	LL mid=(L+R)/2;
	return min(query(2*now,L,mid,x,y),query(2*now+1,mid+1,R,x,y));
}

void update(LL now,LL L,LL R,LL x,LL y,LL val){
	if(L>=x && R<=y){
		updatenode(now,L,R,val);
		return;
	}
	if(L>y || R<x)return;
	LL mid=(L+R)/2;
	pushdown(now,L,R);
	update(2*now,L,mid,x,y,val);
	update(2*now+1,mid+1,R,x,y,val);
	tree[now]=min(tree[2*now],tree[2*now+1]);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	LL n,d,idx=1;
	cin >> n >> d;
	for(LL i=1;i<=n;i++)cin >> arr[i].x >> arr[i].a >> arr[i].b;
	n++;
	arr[n].x=d;arr[n].a=0;arr[n].b=d;
	sort(arr+1,arr+n+1,cmp);
	for(LL i=1;i<=n;i++){
		if(arr[i].x!=arr[i-1].x){
			for(LL j=idx;j<i;j++)nxt[j]=i;
			idx=i;
		}
	}
	nxt[n]=n;
	vector<pii> v;
	for(LL i=1;i<=n;i++)v.push_back({arr[i].b,i});
	sort(v.begin(),v.end());
	//Frem=F-Xi+Sigma(Aj)
	//           Xj<Xi,F<=Bj
	for(auto isi : v){
		update(1,1,n,isi.second,isi.second,-arr[isi.second].x);  //-X[i]
		//Frem bisa dapet benefit A[j] ketika X[j]<X[i]
		update(1,1,n,nxt[isi.second],n,arr[isi.second].a); //Karena awal coba F=min(B[i]) maka semua pom bensin bisa
	}
	LL bef=0;
	idx=0;
	for(LL i=0;i<v.size();i++){
		//Try F=v[i].first
		update(1,1,n,1,n,v[i].first-bef);
		if(i>0 && v[i].first!=bef){
			for(LL j=idx;j<i;j++)update(1,1,n,nxt[v[j].second],n,-arr[v[j].second].a);    //F semakin besar pom yang bisa berbenefit semakin sedikit
			idx=i;
		}
		bef=v[i].first;
		LL minfrem=query(1,1,n,1,n);
		if(minfrem>=0){
			cout << v[i].first-minfrem << '\n';
			return 0;
		}
	}
	return 0;
}

Compilation message

FuelStation.cpp: In function 'int main()':
FuelStation.cpp:78:14: warning: comparison of integer expressions of different signedness: 'LL' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |  for(LL i=0;i<v.size();i++){
      |             ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 39508 KB Output is correct
2 Correct 380 ms 39380 KB Output is correct
3 Correct 411 ms 39380 KB Output is correct
4 Correct 411 ms 39448 KB Output is correct
5 Correct 417 ms 40024 KB Output is correct
6 Correct 417 ms 39000 KB Output is correct
7 Correct 414 ms 38740 KB Output is correct
8 Correct 412 ms 39396 KB Output is correct
9 Correct 434 ms 40004 KB Output is correct
10 Correct 403 ms 38820 KB Output is correct
11 Correct 443 ms 38924 KB Output is correct
12 Correct 363 ms 39380 KB Output is correct
13 Correct 430 ms 38868 KB Output is correct
14 Correct 383 ms 39520 KB Output is correct
15 Correct 373 ms 39524 KB Output is correct
16 Correct 389 ms 40124 KB Output is correct
17 Correct 367 ms 40148 KB Output is correct
18 Correct 380 ms 39392 KB Output is correct
19 Correct 383 ms 39636 KB Output is correct
20 Correct 374 ms 39380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 12 ms 1664 KB Output is correct
3 Correct 11 ms 1664 KB Output is correct
4 Correct 11 ms 1664 KB Output is correct
5 Correct 12 ms 1664 KB Output is correct
6 Correct 13 ms 1664 KB Output is correct
7 Correct 15 ms 1664 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 13 ms 1664 KB Output is correct
15 Correct 19 ms 1664 KB Output is correct
16 Correct 14 ms 1664 KB Output is correct
17 Correct 14 ms 1664 KB Output is correct
18 Correct 14 ms 1664 KB Output is correct
19 Correct 11 ms 1664 KB Output is correct
20 Correct 12 ms 1656 KB Output is correct
21 Correct 11 ms 1664 KB Output is correct
22 Correct 12 ms 1664 KB Output is correct
23 Correct 11 ms 1664 KB Output is correct
24 Correct 11 ms 1664 KB Output is correct
25 Correct 11 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 12 ms 1664 KB Output is correct
3 Correct 11 ms 1664 KB Output is correct
4 Correct 11 ms 1664 KB Output is correct
5 Correct 12 ms 1664 KB Output is correct
6 Correct 13 ms 1664 KB Output is correct
7 Correct 15 ms 1664 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 13 ms 1664 KB Output is correct
15 Correct 19 ms 1664 KB Output is correct
16 Correct 14 ms 1664 KB Output is correct
17 Correct 14 ms 1664 KB Output is correct
18 Correct 14 ms 1664 KB Output is correct
19 Correct 11 ms 1664 KB Output is correct
20 Correct 12 ms 1656 KB Output is correct
21 Correct 11 ms 1664 KB Output is correct
22 Correct 12 ms 1664 KB Output is correct
23 Correct 11 ms 1664 KB Output is correct
24 Correct 11 ms 1664 KB Output is correct
25 Correct 11 ms 1664 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 552 ms 35280 KB Output is correct
28 Correct 572 ms 35028 KB Output is correct
29 Correct 582 ms 34772 KB Output is correct
30 Correct 580 ms 34772 KB Output is correct
31 Correct 591 ms 35416 KB Output is correct
32 Correct 578 ms 35028 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 778 ms 35284 KB Output is correct
40 Correct 793 ms 35284 KB Output is correct
41 Correct 808 ms 35284 KB Output is correct
42 Correct 786 ms 35316 KB Output is correct
43 Correct 849 ms 35388 KB Output is correct
44 Correct 552 ms 34848 KB Output is correct
45 Correct 459 ms 34388 KB Output is correct
46 Correct 562 ms 35416 KB Output is correct
47 Correct 435 ms 36836 KB Output is correct
48 Correct 404 ms 36864 KB Output is correct
49 Correct 558 ms 34644 KB Output is correct
50 Correct 572 ms 35096 KB Output is correct
51 Correct 573 ms 35028 KB Output is correct
52 Correct 527 ms 34772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 360 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 12 ms 1664 KB Output is correct
18 Correct 11 ms 1664 KB Output is correct
19 Correct 11 ms 1664 KB Output is correct
20 Correct 12 ms 1664 KB Output is correct
21 Correct 13 ms 1664 KB Output is correct
22 Correct 15 ms 1664 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 13 ms 1664 KB Output is correct
30 Correct 19 ms 1664 KB Output is correct
31 Correct 14 ms 1664 KB Output is correct
32 Correct 14 ms 1664 KB Output is correct
33 Correct 14 ms 1664 KB Output is correct
34 Correct 11 ms 1664 KB Output is correct
35 Correct 12 ms 1656 KB Output is correct
36 Correct 11 ms 1664 KB Output is correct
37 Correct 12 ms 1664 KB Output is correct
38 Correct 11 ms 1664 KB Output is correct
39 Correct 11 ms 1664 KB Output is correct
40 Correct 11 ms 1664 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 15 ms 1664 KB Output is correct
43 Correct 12 ms 1792 KB Output is correct
44 Correct 13 ms 1792 KB Output is correct
45 Correct 13 ms 1792 KB Output is correct
46 Correct 18 ms 1792 KB Output is correct
47 Correct 12 ms 1792 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 17 ms 1792 KB Output is correct
55 Correct 21 ms 1792 KB Output is correct
56 Correct 15 ms 1792 KB Output is correct
57 Correct 15 ms 1792 KB Output is correct
58 Correct 15 ms 1792 KB Output is correct
59 Correct 14 ms 1792 KB Output is correct
60 Correct 12 ms 1792 KB Output is correct
61 Correct 11 ms 1792 KB Output is correct
62 Correct 28 ms 1792 KB Output is correct
63 Correct 14 ms 1792 KB Output is correct
64 Correct 22 ms 1792 KB Output is correct
65 Correct 13 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 373 ms 39508 KB Output is correct
17 Correct 380 ms 39380 KB Output is correct
18 Correct 411 ms 39380 KB Output is correct
19 Correct 411 ms 39448 KB Output is correct
20 Correct 417 ms 40024 KB Output is correct
21 Correct 417 ms 39000 KB Output is correct
22 Correct 414 ms 38740 KB Output is correct
23 Correct 412 ms 39396 KB Output is correct
24 Correct 434 ms 40004 KB Output is correct
25 Correct 403 ms 38820 KB Output is correct
26 Correct 443 ms 38924 KB Output is correct
27 Correct 363 ms 39380 KB Output is correct
28 Correct 430 ms 38868 KB Output is correct
29 Correct 383 ms 39520 KB Output is correct
30 Correct 373 ms 39524 KB Output is correct
31 Correct 389 ms 40124 KB Output is correct
32 Correct 367 ms 40148 KB Output is correct
33 Correct 380 ms 39392 KB Output is correct
34 Correct 383 ms 39636 KB Output is correct
35 Correct 374 ms 39380 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 12 ms 1664 KB Output is correct
38 Correct 11 ms 1664 KB Output is correct
39 Correct 11 ms 1664 KB Output is correct
40 Correct 12 ms 1664 KB Output is correct
41 Correct 13 ms 1664 KB Output is correct
42 Correct 15 ms 1664 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 13 ms 1664 KB Output is correct
50 Correct 19 ms 1664 KB Output is correct
51 Correct 14 ms 1664 KB Output is correct
52 Correct 14 ms 1664 KB Output is correct
53 Correct 14 ms 1664 KB Output is correct
54 Correct 11 ms 1664 KB Output is correct
55 Correct 12 ms 1656 KB Output is correct
56 Correct 11 ms 1664 KB Output is correct
57 Correct 12 ms 1664 KB Output is correct
58 Correct 11 ms 1664 KB Output is correct
59 Correct 11 ms 1664 KB Output is correct
60 Correct 11 ms 1664 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 552 ms 35280 KB Output is correct
63 Correct 572 ms 35028 KB Output is correct
64 Correct 582 ms 34772 KB Output is correct
65 Correct 580 ms 34772 KB Output is correct
66 Correct 591 ms 35416 KB Output is correct
67 Correct 578 ms 35028 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 0 ms 384 KB Output is correct
73 Correct 1 ms 384 KB Output is correct
74 Correct 778 ms 35284 KB Output is correct
75 Correct 793 ms 35284 KB Output is correct
76 Correct 808 ms 35284 KB Output is correct
77 Correct 786 ms 35316 KB Output is correct
78 Correct 849 ms 35388 KB Output is correct
79 Correct 552 ms 34848 KB Output is correct
80 Correct 459 ms 34388 KB Output is correct
81 Correct 562 ms 35416 KB Output is correct
82 Correct 435 ms 36836 KB Output is correct
83 Correct 404 ms 36864 KB Output is correct
84 Correct 558 ms 34644 KB Output is correct
85 Correct 572 ms 35096 KB Output is correct
86 Correct 573 ms 35028 KB Output is correct
87 Correct 527 ms 34772 KB Output is correct
88 Correct 1 ms 384 KB Output is correct
89 Correct 1 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 1 ms 384 KB Output is correct
93 Correct 1 ms 384 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 360 KB Output is correct
97 Correct 1 ms 384 KB Output is correct
98 Correct 1 ms 384 KB Output is correct
99 Correct 1 ms 384 KB Output is correct
100 Correct 0 ms 384 KB Output is correct
101 Correct 1 ms 384 KB Output is correct
102 Correct 1 ms 384 KB Output is correct
103 Correct 1 ms 384 KB Output is correct
104 Correct 15 ms 1664 KB Output is correct
105 Correct 12 ms 1792 KB Output is correct
106 Correct 13 ms 1792 KB Output is correct
107 Correct 13 ms 1792 KB Output is correct
108 Correct 18 ms 1792 KB Output is correct
109 Correct 12 ms 1792 KB Output is correct
110 Correct 1 ms 384 KB Output is correct
111 Correct 1 ms 384 KB Output is correct
112 Correct 1 ms 384 KB Output is correct
113 Correct 1 ms 384 KB Output is correct
114 Correct 1 ms 384 KB Output is correct
115 Correct 1 ms 384 KB Output is correct
116 Correct 17 ms 1792 KB Output is correct
117 Correct 21 ms 1792 KB Output is correct
118 Correct 15 ms 1792 KB Output is correct
119 Correct 15 ms 1792 KB Output is correct
120 Correct 15 ms 1792 KB Output is correct
121 Correct 14 ms 1792 KB Output is correct
122 Correct 12 ms 1792 KB Output is correct
123 Correct 11 ms 1792 KB Output is correct
124 Correct 28 ms 1792 KB Output is correct
125 Correct 14 ms 1792 KB Output is correct
126 Correct 22 ms 1792 KB Output is correct
127 Correct 13 ms 1664 KB Output is correct
128 Correct 1 ms 384 KB Output is correct
129 Correct 616 ms 38484 KB Output is correct
130 Correct 582 ms 39188 KB Output is correct
131 Correct 613 ms 39644 KB Output is correct
132 Correct 614 ms 39140 KB Output is correct
133 Correct 598 ms 39064 KB Output is correct
134 Correct 621 ms 39728 KB Output is correct
135 Correct 1 ms 384 KB Output is correct
136 Correct 1 ms 384 KB Output is correct
137 Correct 1 ms 416 KB Output is correct
138 Correct 1 ms 384 KB Output is correct
139 Correct 0 ms 384 KB Output is correct
140 Correct 1 ms 384 KB Output is correct
141 Correct 818 ms 39760 KB Output is correct
142 Correct 817 ms 39496 KB Output is correct
143 Correct 822 ms 39704 KB Output is correct
144 Correct 949 ms 39720 KB Output is correct
145 Correct 821 ms 39868 KB Output is correct
146 Correct 703 ms 38048 KB Output is correct
147 Correct 633 ms 38768 KB Output is correct
148 Correct 680 ms 38268 KB Output is correct
149 Correct 638 ms 39124 KB Output is correct
150 Correct 403 ms 39252 KB Output is correct
151 Correct 372 ms 39480 KB Output is correct
152 Correct 596 ms 39084 KB Output is correct
153 Correct 598 ms 38996 KB Output is correct
154 Correct 597 ms 39124 KB Output is correct
155 Correct 616 ms 39260 KB Output is correct