Submission #423833

# Submission time Handle Problem Language Result Execution time Memory
423833 2021-06-11T13:11:57 Z errorgorn Treatment Project (JOI20_treatment) C++17
4 / 100
1437 ms 275704 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back

#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct node{
	int s,e,m;
	set<ii> v;
	node *l,*r;
	
	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	
	void ins(int i,ii j){
		v.insert(j);
		
		if (s==e) return;
		if (i<=m) l->ins(i,j);
		else r->ins(i,j);
	}
	
	void rem(int i,ii j){
		v.erase(j);
		
		if (s==e) return;
		if (i<=m) l->rem(i,j);
		else r->rem(i,j);
	}
	
	int query(int i,int j,int k){
		if (s==i && e==j){
			if (v.empty()) return -1;
			
			if ((*v.begin()).fi<=k) return (*v.begin()).se;
			else return -1;
		}
		else if (j<=m) return l->query(i,j,k);
		else if (m<i) return r->query(i,j,k);
		else{
			int temp=l->query(i,m,k);
			if (temp==-1) return r->query(m+1,j,k);
			else return temp;
		}
	}
} *root1=new node(0,100005),*root2=new node(0,100005);

int n,k;

struct E{
	int l,r;
	int t;
	ll cost;
	
	int dt; //discretized time
};
vector<E> v;

struct upd{
	int segno; //which tree
	int i,j,k;
	ll val;
};

struct cmp{
	bool operator () (upd i,upd j){
		return i.val>j.val;
	}
};

priority_queue<upd,vector<upd>,cmp> pq;

int main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n>>k;
	
	int a,b,c,d;
	rep(x,0,k){
		cin>>a>>b>>c>>d;
		v.pub({b,c+1,a,d});
	}
	
	ll ans=1e18;
	
	rep(x,0,k){
		if (v[x].l==1){
			if (v[x].r==n+1) ans=min(ans,v[x].cost);
			
			pq.push(upd({1,v[x].t,100005,v[x].r+v[x].t,v[x].cost}));
			pq.push(upd({2,0,v[x].t-1,v[x].r-v[x].t,v[x].cost}));
		}
		else{
			root1->ins(v[x].t,ii(v[x].l+v[x].t,x));
			root2->ins(v[x].t,ii(v[x].l-v[x].t,x));
		}
	}
	
	while (!pq.empty()){
		upd u=pq.top();
		pq.pop();
		
		if (u.segno==1){
			while (true){
				int x=root1->query(u.i,u.j,u.k);
				if (x==-1) break;
				
				pq.push(upd({1,v[x].t,100005,v[x].r+v[x].t,v[x].cost+u.val}));
				pq.push(upd({2,0,v[x].t-1,v[x].r-v[x].t,v[x].cost+u.val}));
				
				root1->rem(v[x].t,ii(v[x].l+v[x].t,x));
				root2->rem(v[x].t,ii(v[x].l-v[x].t,x));
				
				if (v[x].r==n+1) ans=min(ans,v[x].cost+u.val);
			}
		}
		else{
			while (true){
				int x=root2->query(u.i,u.j,u.k);
				if (x==-1) break;
				
				pq.push(upd({1,v[x].t,100005,v[x].r+v[x].t,v[x].cost+u.val}));
				pq.push(upd({2,0,v[x].t-1,v[x].r-v[x].t,v[x].cost+u.val}));
				
				root1->rem(v[x].t,ii(v[x].l+v[x].t,x));
				root2->rem(v[x].t,ii(v[x].l-v[x].t,x));
				
				if (v[x].r==n+1) ans=min(ans,v[x].cost+u.val);
			}
		}
	}
	
	if (ans==1e18) cout<<"-1"<<endl;
	else cout<<ans<<endl;
}

Compilation message

treatment.cpp: In constructor 'node::node(int, int)':
treatment.cpp:27:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~
# Verdict Execution time Memory Grader output
1 Correct 1189 ms 266396 KB Output is correct
2 Correct 1032 ms 266460 KB Output is correct
3 Correct 1012 ms 213952 KB Output is correct
4 Correct 1057 ms 213960 KB Output is correct
5 Correct 1409 ms 273364 KB Output is correct
6 Correct 1308 ms 266904 KB Output is correct
7 Correct 1231 ms 266448 KB Output is correct
8 Correct 899 ms 264228 KB Output is correct
9 Correct 769 ms 266184 KB Output is correct
10 Correct 686 ms 266332 KB Output is correct
11 Correct 1416 ms 275664 KB Output is correct
12 Correct 1394 ms 275468 KB Output is correct
13 Correct 1372 ms 275688 KB Output is correct
14 Correct 1437 ms 275464 KB Output is correct
15 Correct 1372 ms 266744 KB Output is correct
16 Correct 1345 ms 266488 KB Output is correct
17 Correct 1357 ms 266516 KB Output is correct
18 Correct 1238 ms 275704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 64 ms 76580 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 64 ms 76580 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1189 ms 266396 KB Output is correct
2 Correct 1032 ms 266460 KB Output is correct
3 Correct 1012 ms 213952 KB Output is correct
4 Correct 1057 ms 213960 KB Output is correct
5 Correct 1409 ms 273364 KB Output is correct
6 Correct 1308 ms 266904 KB Output is correct
7 Correct 1231 ms 266448 KB Output is correct
8 Correct 899 ms 264228 KB Output is correct
9 Correct 769 ms 266184 KB Output is correct
10 Correct 686 ms 266332 KB Output is correct
11 Correct 1416 ms 275664 KB Output is correct
12 Correct 1394 ms 275468 KB Output is correct
13 Correct 1372 ms 275688 KB Output is correct
14 Correct 1437 ms 275464 KB Output is correct
15 Correct 1372 ms 266744 KB Output is correct
16 Correct 1345 ms 266488 KB Output is correct
17 Correct 1357 ms 266516 KB Output is correct
18 Correct 1238 ms 275704 KB Output is correct
19 Runtime error 64 ms 76580 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -