답안 #317753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317753 2020-10-30T09:43:38 Z kaitran1112 운세 보기 2 (JOI14_fortune_telling2) C++14
100 / 100
377 ms 51060 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);
}
main()
{
	//file();
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	in();
	solve();
}

Compilation message

fortune_telling2.cpp: In function 'long long int get(long long 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: At global scope:
fortune_telling2.cpp:78:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   78 | main()
      |      ^
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);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 14 ms 3072 KB Output is correct
15 Correct 28 ms 5628 KB Output is correct
16 Correct 45 ms 8048 KB Output is correct
17 Correct 60 ms 10740 KB Output is correct
18 Correct 59 ms 10740 KB Output is correct
19 Correct 59 ms 10740 KB Output is correct
20 Correct 62 ms 10740 KB Output is correct
21 Correct 54 ms 10740 KB Output is correct
22 Correct 45 ms 10748 KB Output is correct
23 Correct 45 ms 10740 KB Output is correct
24 Correct 45 ms 10748 KB Output is correct
25 Correct 44 ms 10876 KB Output is correct
26 Correct 48 ms 10620 KB Output is correct
27 Correct 56 ms 10736 KB Output is correct
28 Correct 53 ms 10740 KB Output is correct
29 Correct 59 ms 10740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 14 ms 3072 KB Output is correct
15 Correct 28 ms 5628 KB Output is correct
16 Correct 45 ms 8048 KB Output is correct
17 Correct 60 ms 10740 KB Output is correct
18 Correct 59 ms 10740 KB Output is correct
19 Correct 59 ms 10740 KB Output is correct
20 Correct 62 ms 10740 KB Output is correct
21 Correct 54 ms 10740 KB Output is correct
22 Correct 45 ms 10748 KB Output is correct
23 Correct 45 ms 10740 KB Output is correct
24 Correct 45 ms 10748 KB Output is correct
25 Correct 44 ms 10876 KB Output is correct
26 Correct 48 ms 10620 KB Output is correct
27 Correct 56 ms 10736 KB Output is correct
28 Correct 53 ms 10740 KB Output is correct
29 Correct 59 ms 10740 KB Output is correct
30 Correct 172 ms 45032 KB Output is correct
31 Correct 213 ms 46952 KB Output is correct
32 Correct 263 ms 47844 KB Output is correct
33 Correct 362 ms 50912 KB Output is correct
34 Correct 179 ms 44520 KB Output is correct
35 Correct 366 ms 51060 KB Output is correct
36 Correct 364 ms 50784 KB Output is correct
37 Correct 362 ms 50788 KB Output is correct
38 Correct 358 ms 50912 KB Output is correct
39 Correct 377 ms 50864 KB Output is correct
40 Correct 314 ms 50784 KB Output is correct
41 Correct 361 ms 50912 KB Output is correct
42 Correct 355 ms 50784 KB Output is correct
43 Correct 243 ms 50788 KB Output is correct
44 Correct 243 ms 50912 KB Output is correct
45 Correct 247 ms 50912 KB Output is correct
46 Correct 260 ms 50792 KB Output is correct
47 Correct 257 ms 50792 KB Output is correct
48 Correct 315 ms 50408 KB Output is correct
49 Correct 318 ms 50148 KB Output is correct