Submission #317752

# Submission time Handle Problem Language Result Execution time Memory
317752 2020-10-30T09:43:01 Z kaitran1112 Fortune Telling 2 (JOI14_fortune_telling2) C++14
0 / 100
1 ms 512 KB
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define fi first
#define se second 
#define pb push_back
#define trash trash
#define ALL(x) x.begin(),x.end()
const int oo=1e9;
const int Mod=1e9+7;
const long long OO=1e18;
const int N=1e6+5;
int n, k, ans, a[N], b[N], c[N], mp[N][25], f[N];
vector<int>vc;
vector<ii>querry;
///////////////////24<3/////////////////
void upd(int x)
{
	for(;x; x-=x&-x)f[x]++;
}
int get(int x)
{
	int res = 0;
	for(;x<=k;x+=x&-x)res+=f[x]; return res;
}
int get_max(int l, int r)
{
	if(l>r)return 0;
	int t = log2(r-l+1);
	return max(mp[l][t], mp[r-(1<<t)+1][t]);
}
void in()
{
	cin >> n >> k;
	for(int i=1; i<=n; i++)cin >> a[i] >> b[i];
	for(int i=1; i<=k; i++)
	{
		cin >> c[i]; vc.pb(c[i]);
	}
	sort(vc.begin(),vc.end());
	for(int i=1; i<=k; i++) c[i] = lower_bound(ALL(vc),c[i]) - vc.begin()+1;
	for(int i=1; i<=k; i++)mp[c[i]][0] = i;
	for(int i=1; i<=20; i++)
		for(int j=1; j<=k; j++)mp[j][i] = max(mp[j][i-1], mp[j+(1<<(i-1))][i-1]);
}	
void solve()
{
	for(int i=1; i<=n; i++)
	{
		int x = a[i], y = b[i]; if(x>y)swap(x,y);
		x = lower_bound(ALL(vc),x) - vc.begin()+1;
		y = lower_bound(ALL(vc),y) - vc.begin();
		querry.pb({get_max(x,y),i});
	}
	sort(ALL(querry));
	int cur = 0;
	for(ii x : querry)
	{
		int pos = x.fi, i = x.se;
		while(cur < pos)upd(c[cur++]);
		int Max = max(a[i],b[i]); Max = lower_bound(ALL(vc),Max) - vc.begin() + 1;
		int cnt = k - Max + 1; 
		cnt -= get(Max);
		if(pos)ans += (a[i]<b[i])^(cnt%2) ? b[i] : a[i];
		else ans += cnt%2 ? b[i] : a[i];
	}
	cout << ans;
}
///////////////////24<3/////////////////
void file()
{
	if(fopen("trash.inp", "r"))
    	freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
 		// else freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
}
int main()
{
	file();
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	in();
	solve();
}

Compilation message

fortune_telling2.cpp: In function 'int get(int)':
fortune_telling2.cpp:26:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   26 |  for(;x<=k;x+=x&-x)res+=f[x]; return res;
      |  ^~~
fortune_telling2.cpp:26:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   26 |  for(;x<=k;x+=x&-x)res+=f[x]; return res;
      |                               ^~~~~~
fortune_telling2.cpp: In function 'void file()':
fortune_telling2.cpp:75:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   75 |      freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:75:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   75 |      freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -