Submission #289611

# Submission time Handle Problem Language Result Execution time Memory
289611 2020-09-02T19:02:13 Z TadijaSebez Treatment Project (JOI20_treatment) C++11
100 / 100
978 ms 51248 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
const int N=100050;
const ll inf=9e18;
struct project{
	int t,l,r,c;
	project(){}
	project(int a,int b,int d,int e):t(a),l(b),r(d),c(e){}
	bool operator < (project b){return l+r<b.l+b.r||(l+r==b.l+b.r&&t<b.t);}
}pro[N];
ll dist[N];
set<pair<int,int>> bit[N];
vector<pair<int,pii>> save;
vector<int> cor;
void AddPt(int x,int y,int idx){
	save.pb({idx,{x,y}});
	cor.pb(x);
}
int Find(int x){return lower_bound(cor.begin(),cor.end(),x)-cor.begin()+1;}
void AddBIT(int x,int y,int idx){
	//printf("Add %i %i %i\n",x,y,idx);
	x=Find(x);
	for(int i=x;i>=1;i-=i&-i)bit[i].insert({y,idx});
}
void DelBIT(int x,int y,int idx){
	//printf("Del %i %i %i\n",x,y,idx);
	x=Find(x);
	for(int i=x;i>=1;i-=i&-i)bit[i].erase({y,idx});
}
void Build(){
	sort(cor.begin(),cor.end());
	cor.erase(unique(cor.begin(),cor.end()),cor.end());
	for(auto o:save){
		AddBIT(o.second.first,o.second.second,o.first);
	}
}
int Get(pair<ll,pii> now){
	//printf("%lld %i %i\n",now.first,now.second.first,now.second.second);
	int x=Find(now.second.first);
	for(int i=x;i<=cor.size();i+=i&-i){
		auto it=bit[i].lower_bound({now.second.second,0});
		if(it!=bit[i].end())return it->second;
	}
	return 0;
}
int n,m;
int main(){
	scanf("%i %i",&n,&m);
	for(int i=1;i<=m;i++)scanf("%i %i %i %i",&pro[i].t,&pro[i].l,&pro[i].r,&pro[i].c);
	set<pair<ll,pii>> st;
	ll ans=inf;
	for(int i=1;i<=m;i++){
		if(pro[i].r==n){
			if(pro[i].l==1)ans=min(ans,(ll)pro[i].c);
			st.insert({pro[i].c,{pro[i].l+pro[i].t,pro[i].l-pro[i].t}});
		}else{
			AddPt(pro[i].r+1+pro[i].t,pro[i].r+1-pro[i].t,i);
		}
	}
	Build();
	while(st.size()){
		int u=Get(*st.begin());
		//printf("%i %lld\n",u,st.begin()->first);
		if(u==0){
			st.erase(st.begin());
			continue;
		}
		DelBIT(pro[u].r+1+pro[u].t,pro[u].r+1-pro[u].t,u);
		dist[u]=st.begin()->first+pro[u].c;
		//printf("%i %lld\n",u,dist[u]);
		if(pro[u].l==1)ans=min(ans,dist[u]);
		st.insert({dist[u],{pro[u].l+pro[u].t,pro[u].l-pro[u].t}});
	}
	printf("%lld\n",ans==inf?-1:ans);
	return 0;
}

Compilation message

treatment.cpp: In function 'int Get(std::pair<long long int, std::pair<int, int> >)':
treatment.cpp:43:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for(int i=x;i<=cor.size();i+=i&-i){
      |              ~^~~~~~~~~~~~
treatment.cpp: In function 'int main()':
treatment.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |  scanf("%i %i",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~~
treatment.cpp:52:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |  for(int i=1;i<=m;i++)scanf("%i %i %i %i",&pro[i].t,&pro[i].l,&pro[i].r,&pro[i].c);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 492 ms 47268 KB Output is correct
2 Correct 457 ms 47148 KB Output is correct
3 Correct 329 ms 35272 KB Output is correct
4 Correct 331 ms 35152 KB Output is correct
5 Correct 256 ms 26920 KB Output is correct
6 Correct 256 ms 35520 KB Output is correct
7 Correct 245 ms 42540 KB Output is correct
8 Correct 139 ms 26156 KB Output is correct
9 Correct 172 ms 34472 KB Output is correct
10 Correct 169 ms 41640 KB Output is correct
11 Correct 341 ms 32560 KB Output is correct
12 Correct 331 ms 32344 KB Output is correct
13 Correct 623 ms 50348 KB Output is correct
14 Correct 625 ms 50216 KB Output is correct
15 Correct 544 ms 50500 KB Output is correct
16 Correct 531 ms 50348 KB Output is correct
17 Correct 527 ms 49704 KB Output is correct
18 Correct 314 ms 31792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 3 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 3 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 3 ms 4992 KB Output is correct
17 Correct 3 ms 4992 KB Output is correct
18 Correct 3 ms 4992 KB Output is correct
19 Correct 3 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 3 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 3 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 3 ms 4992 KB Output is correct
17 Correct 3 ms 4992 KB Output is correct
18 Correct 3 ms 4992 KB Output is correct
19 Correct 3 ms 4992 KB Output is correct
20 Correct 12 ms 6272 KB Output is correct
21 Correct 12 ms 6272 KB Output is correct
22 Correct 17 ms 6656 KB Output is correct
23 Correct 15 ms 6656 KB Output is correct
24 Correct 16 ms 6528 KB Output is correct
25 Correct 18 ms 6656 KB Output is correct
26 Correct 17 ms 6656 KB Output is correct
27 Correct 12 ms 6656 KB Output is correct
28 Correct 17 ms 6528 KB Output is correct
29 Correct 17 ms 6656 KB Output is correct
30 Correct 11 ms 6656 KB Output is correct
31 Correct 11 ms 6656 KB Output is correct
32 Correct 13 ms 6144 KB Output is correct
33 Correct 12 ms 6016 KB Output is correct
34 Correct 17 ms 6784 KB Output is correct
35 Correct 13 ms 6016 KB Output is correct
36 Correct 12 ms 6016 KB Output is correct
37 Correct 16 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 492 ms 47268 KB Output is correct
2 Correct 457 ms 47148 KB Output is correct
3 Correct 329 ms 35272 KB Output is correct
4 Correct 331 ms 35152 KB Output is correct
5 Correct 256 ms 26920 KB Output is correct
6 Correct 256 ms 35520 KB Output is correct
7 Correct 245 ms 42540 KB Output is correct
8 Correct 139 ms 26156 KB Output is correct
9 Correct 172 ms 34472 KB Output is correct
10 Correct 169 ms 41640 KB Output is correct
11 Correct 341 ms 32560 KB Output is correct
12 Correct 331 ms 32344 KB Output is correct
13 Correct 623 ms 50348 KB Output is correct
14 Correct 625 ms 50216 KB Output is correct
15 Correct 544 ms 50500 KB Output is correct
16 Correct 531 ms 50348 KB Output is correct
17 Correct 527 ms 49704 KB Output is correct
18 Correct 314 ms 31792 KB Output is correct
19 Correct 3 ms 4992 KB Output is correct
20 Correct 3 ms 4992 KB Output is correct
21 Correct 3 ms 4992 KB Output is correct
22 Correct 4 ms 4992 KB Output is correct
23 Correct 3 ms 4992 KB Output is correct
24 Correct 3 ms 4992 KB Output is correct
25 Correct 3 ms 4992 KB Output is correct
26 Correct 3 ms 4992 KB Output is correct
27 Correct 3 ms 4992 KB Output is correct
28 Correct 3 ms 4992 KB Output is correct
29 Correct 4 ms 4992 KB Output is correct
30 Correct 3 ms 4992 KB Output is correct
31 Correct 3 ms 4992 KB Output is correct
32 Correct 3 ms 4992 KB Output is correct
33 Correct 3 ms 4992 KB Output is correct
34 Correct 3 ms 4992 KB Output is correct
35 Correct 3 ms 4992 KB Output is correct
36 Correct 3 ms 4992 KB Output is correct
37 Correct 3 ms 4992 KB Output is correct
38 Correct 12 ms 6272 KB Output is correct
39 Correct 12 ms 6272 KB Output is correct
40 Correct 17 ms 6656 KB Output is correct
41 Correct 15 ms 6656 KB Output is correct
42 Correct 16 ms 6528 KB Output is correct
43 Correct 18 ms 6656 KB Output is correct
44 Correct 17 ms 6656 KB Output is correct
45 Correct 12 ms 6656 KB Output is correct
46 Correct 17 ms 6528 KB Output is correct
47 Correct 17 ms 6656 KB Output is correct
48 Correct 11 ms 6656 KB Output is correct
49 Correct 11 ms 6656 KB Output is correct
50 Correct 13 ms 6144 KB Output is correct
51 Correct 12 ms 6016 KB Output is correct
52 Correct 17 ms 6784 KB Output is correct
53 Correct 13 ms 6016 KB Output is correct
54 Correct 12 ms 6016 KB Output is correct
55 Correct 16 ms 6656 KB Output is correct
56 Correct 361 ms 37792 KB Output is correct
57 Correct 441 ms 41000 KB Output is correct
58 Correct 530 ms 49452 KB Output is correct
59 Correct 508 ms 49852 KB Output is correct
60 Correct 703 ms 50600 KB Output is correct
61 Correct 526 ms 49452 KB Output is correct
62 Correct 358 ms 37680 KB Output is correct
63 Correct 496 ms 50472 KB Output is correct
64 Correct 529 ms 50476 KB Output is correct
65 Correct 500 ms 50596 KB Output is correct
66 Correct 536 ms 50588 KB Output is correct
67 Correct 808 ms 51008 KB Output is correct
68 Correct 639 ms 51208 KB Output is correct
69 Correct 434 ms 51112 KB Output is correct
70 Correct 824 ms 50984 KB Output is correct
71 Correct 632 ms 51116 KB Output is correct
72 Correct 439 ms 51128 KB Output is correct
73 Correct 849 ms 51004 KB Output is correct
74 Correct 350 ms 50344 KB Output is correct
75 Correct 264 ms 50344 KB Output is correct
76 Correct 361 ms 33068 KB Output is correct
77 Correct 454 ms 33200 KB Output is correct
78 Correct 652 ms 50604 KB Output is correct
79 Correct 924 ms 51116 KB Output is correct
80 Correct 565 ms 50864 KB Output is correct
81 Correct 580 ms 50856 KB Output is correct
82 Correct 569 ms 49832 KB Output is correct
83 Correct 708 ms 50088 KB Output is correct
84 Correct 919 ms 50312 KB Output is correct
85 Correct 693 ms 51072 KB Output is correct
86 Correct 702 ms 51244 KB Output is correct
87 Correct 750 ms 51040 KB Output is correct
88 Correct 558 ms 51116 KB Output is correct
89 Correct 722 ms 51112 KB Output is correct
90 Correct 911 ms 50232 KB Output is correct
91 Correct 926 ms 51104 KB Output is correct
92 Correct 874 ms 51248 KB Output is correct
93 Correct 931 ms 51240 KB Output is correct
94 Correct 689 ms 51244 KB Output is correct
95 Correct 845 ms 51144 KB Output is correct
96 Correct 883 ms 50296 KB Output is correct
97 Correct 906 ms 50264 KB Output is correct
98 Correct 895 ms 50160 KB Output is correct
99 Correct 922 ms 50088 KB Output is correct
100 Correct 703 ms 43176 KB Output is correct
101 Correct 978 ms 51196 KB Output is correct
102 Correct 672 ms 42028 KB Output is correct
103 Correct 886 ms 51116 KB Output is correct