Submission #239718

# Submission time Handle Problem Language Result Execution time Memory
239718 2020-06-17T08:10:25 Z MvC Fortune Telling 2 (JOI14_fortune_telling2) C++11
100 / 100
388 ms 20308 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
#define all(x) x.begin(),x.end()
#define lun(x) (int)x.size()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<60);
const int inf=(1<<30);
const int nmax=2e5+50;
const ll mod=1e9+7;
using namespace std;
int n,k,i,j,x,mn,mx,a[nmax],b[nmax],q[nmax],st[4*nmax],fw[nmax],sw[nmax],sz;
ll rs;
vector<int>vc;
vector<pair<int,int> >vec[nmax];
void ufw(int i)
{
	for(;i>=1;i-=i&(-i))fw[i]++;
}
int qfw(int i)
{
	int ans=0;
	for(;i<=sz;i+=i&(-i))ans+=fw[i];
	return ans;
}
void upd(int nod,int l,int r,int p,int v)
{
	if(l==r)
	{
		st[nod]=v;
		return;
	}
	int mid=(l+r)/2;
	if(p<=mid)upd(2*nod,l,mid,p,v);
	else upd(2*nod+1,mid+1,r,p,v);
	st[nod]=max(st[2*nod],st[2*nod+1]);
}
int qry(int nod,int l,int r,int tl,int tr)
{
	if(tr<l || tl>r)return 0;
	if(tl<=l && r<=tr)return st[nod];
	int mid=(l+r)/2;
	return max(qry(2*nod,l,mid,tl,tr),qry(2*nod+1,mid+1,r,tl,tr));
}
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>>k;
	for(i=1;i<=n;i++)cin>>a[i]>>b[i];
	for(i=1;i<=k;i++)
	{
		cin>>q[i];
		vc.pb(q[i]);
	}
	sort(all(vc));
	vc.resize(unique(all(vc))-vc.begin());
	sz=lun(vc);
	for(i=1;i<=k;i++)
	{
		q[i]=lower_bound(all(vc),q[i])-vc.begin()+1;
		upd(1,1,sz,q[i],i);
	}
	for(i=1;i<=n;i++)
	{
		mn=min(a[i],b[i]),mx=max(a[i],b[i]);
		mn=lower_bound(all(vc),mn)-vc.begin()+1;
		mx=lower_bound(all(vc),mx)-vc.begin();
		x=0;
		if(mn<=mx && mx<=sz)x=qry(1,1,sz,mn,mx);
		if(x)
		{
			sw[i]=1;
			if(a[i]>b[i])swap(a[i],b[i]);
		}
		vec[x].pb(mkp(i,mx+1));
	}
	for(i=k;i>=0;i--)
	{
		for(j=0;j<lun(vec[i]);j++)sw[vec[i][j].fr]^=(qfw(vec[i][j].sc)&1);
		if(i)ufw(q[i]);
	}
	for(i=1;i<=n;i++)
	{
		if(sw[i])rs+=1LL*b[i];
		else rs+=1LL*a[i];
	}
	cout<<rs<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5120 KB Output is correct
2 Correct 9 ms 5120 KB Output is correct
3 Correct 9 ms 5120 KB Output is correct
4 Correct 11 ms 5120 KB Output is correct
5 Correct 9 ms 5120 KB Output is correct
6 Correct 10 ms 5120 KB Output is correct
7 Correct 9 ms 5120 KB Output is correct
8 Correct 11 ms 5120 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 9 ms 5124 KB Output is correct
11 Correct 9 ms 5120 KB Output is correct
12 Correct 9 ms 5120 KB Output is correct
13 Correct 9 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5120 KB Output is correct
2 Correct 9 ms 5120 KB Output is correct
3 Correct 9 ms 5120 KB Output is correct
4 Correct 11 ms 5120 KB Output is correct
5 Correct 9 ms 5120 KB Output is correct
6 Correct 10 ms 5120 KB Output is correct
7 Correct 9 ms 5120 KB Output is correct
8 Correct 11 ms 5120 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 9 ms 5124 KB Output is correct
11 Correct 9 ms 5120 KB Output is correct
12 Correct 9 ms 5120 KB Output is correct
13 Correct 9 ms 5120 KB Output is correct
14 Correct 21 ms 5888 KB Output is correct
15 Correct 37 ms 6648 KB Output is correct
16 Correct 48 ms 7288 KB Output is correct
17 Correct 70 ms 8176 KB Output is correct
18 Correct 65 ms 8180 KB Output is correct
19 Correct 62 ms 8184 KB Output is correct
20 Correct 65 ms 8188 KB Output is correct
21 Correct 66 ms 8180 KB Output is correct
22 Correct 49 ms 7412 KB Output is correct
23 Correct 53 ms 7280 KB Output is correct
24 Correct 52 ms 7416 KB Output is correct
25 Correct 49 ms 7644 KB Output is correct
26 Correct 58 ms 7928 KB Output is correct
27 Correct 59 ms 8184 KB Output is correct
28 Correct 61 ms 8184 KB Output is correct
29 Correct 55 ms 8176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5120 KB Output is correct
2 Correct 9 ms 5120 KB Output is correct
3 Correct 9 ms 5120 KB Output is correct
4 Correct 11 ms 5120 KB Output is correct
5 Correct 9 ms 5120 KB Output is correct
6 Correct 10 ms 5120 KB Output is correct
7 Correct 9 ms 5120 KB Output is correct
8 Correct 11 ms 5120 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 9 ms 5124 KB Output is correct
11 Correct 9 ms 5120 KB Output is correct
12 Correct 9 ms 5120 KB Output is correct
13 Correct 9 ms 5120 KB Output is correct
14 Correct 21 ms 5888 KB Output is correct
15 Correct 37 ms 6648 KB Output is correct
16 Correct 48 ms 7288 KB Output is correct
17 Correct 70 ms 8176 KB Output is correct
18 Correct 65 ms 8180 KB Output is correct
19 Correct 62 ms 8184 KB Output is correct
20 Correct 65 ms 8188 KB Output is correct
21 Correct 66 ms 8180 KB Output is correct
22 Correct 49 ms 7412 KB Output is correct
23 Correct 53 ms 7280 KB Output is correct
24 Correct 52 ms 7416 KB Output is correct
25 Correct 49 ms 7644 KB Output is correct
26 Correct 58 ms 7928 KB Output is correct
27 Correct 59 ms 8184 KB Output is correct
28 Correct 61 ms 8184 KB Output is correct
29 Correct 55 ms 8176 KB Output is correct
30 Correct 139 ms 11888 KB Output is correct
31 Correct 177 ms 13564 KB Output is correct
32 Correct 268 ms 15728 KB Output is correct
33 Correct 378 ms 20208 KB Output is correct
34 Correct 130 ms 11500 KB Output is correct
35 Correct 360 ms 20308 KB Output is correct
36 Correct 388 ms 19816 KB Output is correct
37 Correct 344 ms 19824 KB Output is correct
38 Correct 340 ms 20204 KB Output is correct
39 Correct 352 ms 19748 KB Output is correct
40 Correct 309 ms 19344 KB Output is correct
41 Correct 371 ms 19692 KB Output is correct
42 Correct 338 ms 19824 KB Output is correct
43 Correct 227 ms 18636 KB Output is correct
44 Correct 245 ms 18668 KB Output is correct
45 Correct 238 ms 18540 KB Output is correct
46 Correct 240 ms 17580 KB Output is correct
47 Correct 231 ms 16364 KB Output is correct
48 Correct 285 ms 19948 KB Output is correct
49 Correct 265 ms 20204 KB Output is correct