답안 #729640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729640 2023-04-24T10:13:51 Z myrcella Pinball (JOI14_pinball) C++17
100 / 100
425 ms 38732 KB
//by szh
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn = 3e5+10;

int n,m;
map <int,int> mp;
int a[maxn],b[maxn],c[maxn],d[maxn];
pll tree[maxn*4];
ll big = 1e18;

void update(int c,int cl,int cr,int pos,pll val) {
	if (cl==cr) tree[c].fi = min(val.fi,tree[c].fi),tree[c].se = min(val.se,tree[c].se);
	else {
		int mid=cl+cr>>1;
		if (pos<=mid) update(c<<1,cl,mid,pos,val);
		else update(c<<1|1,mid+1,cr,pos,val);
		tree[c].fi = min(tree[c<<1].fi,tree[c<<1|1].fi);
		tree[c].se = min(tree[c<<1].se,tree[c<<1|1].se);
	}
}

pll query(int c,int cl,int cr,int l,int r) {
	if (l<=cl and cr<=r) return tree[c];
	int mid = cl+cr>>1;
	pll ret = {big,big};
	if (l<=mid) ret = query(c<<1,cl,mid,l,r);
	if (r>mid) {
		pll tmp = query(c<<1|1,mid+1,cr,l,r);
		ret.fi = min(ret.fi,tmp.fi);
		ret.se = min(ret.se,tmp.se);
	}
	return ret;
}

int main() {
//	freopen("input.txt","r",stdin);	
	std::ios::sync_with_stdio(false);cin.tie(0);
	cin>>n>>m;
	ll ans = big;
	rep(i,0,maxn*4) tree[i] = {big,big};
	mp[1] = mp[m] = 1;
	rep(i,0,n) {
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		mp[a[i]]=1,mp[b[i]]=1,mp[c[i]]=1;
	}
	int tot = 0;
	for (auto &it:mp) it.se=++tot;
	rep(i,0,n) a[i] = mp[a[i]], b[i] = mp[b[i]], c[i] = mp[c[i]];
	rep(i,0,n) {
		pll tmp = query(1,1,tot,a[i],b[i]);
//		debug(tmp.se);
		pll cur = {big,big};
		if (a[i]==1) cur.fi=d[i];
		else cur.fi = tmp.fi + d[i];
		if (b[i]==tot) cur.se = d[i];
		else cur.se = tmp.se + d[i];
		if (cur.fi < big or cur.se<big) {
			update(1,1,tot,c[i],cur);
			ans = min(ans,cur.fi+cur.se-d[i]);
		}
//		debug(c[i]),debug(cur.fi),debug(cur.se);
	}
	if (ans==big) cout<<-1;
	else cout<<ans;
	return 0;
}

Compilation message

pinball.cpp: In function 'void update(int, int, int, int, std::pair<long long int, long long int>)':
pinball.cpp:35:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |   int mid=cl+cr>>1;
      |           ~~^~~
pinball.cpp: In function 'std::pair<long long int, long long int> query(int, int, int, int, int)':
pinball.cpp:45:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |  int mid = cl+cr>>1;
      |            ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 19028 KB Output is correct
2 Correct 9 ms 19016 KB Output is correct
3 Correct 9 ms 19072 KB Output is correct
4 Correct 10 ms 19036 KB Output is correct
5 Correct 9 ms 19016 KB Output is correct
6 Correct 10 ms 19028 KB Output is correct
7 Correct 9 ms 19044 KB Output is correct
8 Correct 12 ms 19020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 19028 KB Output is correct
2 Correct 9 ms 19016 KB Output is correct
3 Correct 9 ms 19072 KB Output is correct
4 Correct 10 ms 19036 KB Output is correct
5 Correct 9 ms 19016 KB Output is correct
6 Correct 10 ms 19028 KB Output is correct
7 Correct 9 ms 19044 KB Output is correct
8 Correct 12 ms 19020 KB Output is correct
9 Correct 8 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 9 ms 19152 KB Output is correct
12 Correct 10 ms 19156 KB Output is correct
13 Correct 9 ms 19156 KB Output is correct
14 Correct 9 ms 19076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 19028 KB Output is correct
2 Correct 9 ms 19016 KB Output is correct
3 Correct 9 ms 19072 KB Output is correct
4 Correct 10 ms 19036 KB Output is correct
5 Correct 9 ms 19016 KB Output is correct
6 Correct 10 ms 19028 KB Output is correct
7 Correct 9 ms 19044 KB Output is correct
8 Correct 12 ms 19020 KB Output is correct
9 Correct 8 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 9 ms 19152 KB Output is correct
12 Correct 10 ms 19156 KB Output is correct
13 Correct 9 ms 19156 KB Output is correct
14 Correct 9 ms 19076 KB Output is correct
15 Correct 9 ms 19028 KB Output is correct
16 Correct 9 ms 19124 KB Output is correct
17 Correct 12 ms 19164 KB Output is correct
18 Correct 9 ms 19156 KB Output is correct
19 Correct 11 ms 19220 KB Output is correct
20 Correct 11 ms 19160 KB Output is correct
21 Correct 10 ms 19148 KB Output is correct
22 Correct 10 ms 19284 KB Output is correct
23 Correct 10 ms 19324 KB Output is correct
24 Correct 10 ms 19240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 19028 KB Output is correct
2 Correct 9 ms 19016 KB Output is correct
3 Correct 9 ms 19072 KB Output is correct
4 Correct 10 ms 19036 KB Output is correct
5 Correct 9 ms 19016 KB Output is correct
6 Correct 10 ms 19028 KB Output is correct
7 Correct 9 ms 19044 KB Output is correct
8 Correct 12 ms 19020 KB Output is correct
9 Correct 8 ms 19156 KB Output is correct
10 Correct 13 ms 19156 KB Output is correct
11 Correct 9 ms 19152 KB Output is correct
12 Correct 10 ms 19156 KB Output is correct
13 Correct 9 ms 19156 KB Output is correct
14 Correct 9 ms 19076 KB Output is correct
15 Correct 9 ms 19028 KB Output is correct
16 Correct 9 ms 19124 KB Output is correct
17 Correct 12 ms 19164 KB Output is correct
18 Correct 9 ms 19156 KB Output is correct
19 Correct 11 ms 19220 KB Output is correct
20 Correct 11 ms 19160 KB Output is correct
21 Correct 10 ms 19148 KB Output is correct
22 Correct 10 ms 19284 KB Output is correct
23 Correct 10 ms 19324 KB Output is correct
24 Correct 10 ms 19240 KB Output is correct
25 Correct 25 ms 20296 KB Output is correct
26 Correct 60 ms 22988 KB Output is correct
27 Correct 180 ms 27456 KB Output is correct
28 Correct 113 ms 24544 KB Output is correct
29 Correct 148 ms 26056 KB Output is correct
30 Correct 197 ms 25316 KB Output is correct
31 Correct 413 ms 32460 KB Output is correct
32 Correct 316 ms 30184 KB Output is correct
33 Correct 39 ms 22796 KB Output is correct
34 Correct 140 ms 28876 KB Output is correct
35 Correct 179 ms 38604 KB Output is correct
36 Correct 425 ms 38732 KB Output is correct
37 Correct 334 ms 38676 KB Output is correct
38 Correct 276 ms 38608 KB Output is correct