답안 #95140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
95140 2019-01-27T15:47:18 Z MvC 운세 보기 2 (JOI14_fortune_telling2) C++11
0 / 100
7 ms 5320 KB
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int a[nmax],b[nmax],q[nmax],n,m,i,j,t,sp[20][nmax],fw[nmax],sz,ans[nmax],cur,l,r;
ll sum;
vector<int>v;
vector<pair<int,int> >vc[nmax];
void upd(int i)
{
	for(;i>=1;i-=i&(-i))fw[i]++;
}
int qry(int i)
{
	int rs=0;
	for(;i<=sz;i+=i&(-i))rs+=fw[i];
	return rs;
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>m;
	for(i=1;i<=n;i++)cin>>a[i]>>b[i];
	for(i=1;i<=m;i++)
	{
		cin>>q[i];
		v.pb(q[i]);
	}
	sort(v.begin(),v.end());
	v.resize(unique(v.begin(),v.end())-v.begin());
	sz=v.size();
	for(i=1;i<=m;i++)
	{
		q[i]=lower_bound(v.begin(),v.end(),q[i])-v.begin()+1;
		sp[0][q[i]]=++t;
	}
	for(i=1;(1<<i)<=sz;i++)for(j=1;j+(1<<i)<=sz+1;j++)sp[i][j]=max(sp[i-1][j],sp[i-1][j+(1<<i)]);
	for(i=1;i<=n;i++)
	{
		l=min(a[i],b[i]);
		r=max(a[i],b[i]);
		l=lower_bound(v.begin(),v.end(),l)-v.begin()+1;
		r=lower_bound(v.begin(),v.end(),r)-v.begin()+1;
		cur=0;
		for(j=19;j>=0;j--)if(l+(1<<j)<=r)cur=max(cur,sp[j][l]),l+=(1<<j);
		if(cur!=0)
		{
			ans[i]=1;
			if(a[i]>b[i])swap(a[i],b[i]);
		}
		vc[cur].pb({i,r});
	}
	for(i=m;i>=0;i--)
	{
		for(j=0;j<vc[i].size();j++)ans[vc[i][j].fr]^=qry(vc[i][j].sc)&1;
		if(i)upd(q[i]);
	}
	for(i=1;i<=n;i++)
	{
		if(ans[i])sum+=1LL*b[i];
		else sum+=1LL*a[i];
	}
	cout<<sum<<endl;
    return 0;
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:70:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<vc[i].size();j++)ans[vc[i][j].fr]^=qry(vc[i][j].sc)&1;
           ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 5320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 5320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 5320 KB Output isn't correct
2 Halted 0 ms 0 KB -