Submission #126641

# Submission time Handle Problem Language Result Execution time Memory
126641 2019-07-08T08:15:25 Z fjzzq2002 Fortune Telling 2 (JOI14_fortune_telling2) C++14
100 / 100
461 ms 33272 KB
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
#include <assert.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 2234567
int n,k,a[SZ],b[SZ],t[SZ],ls[SZ],ln,A[SZ],B[SZ];
int id[SZ];
bool cmp(int x,int y)
{
	return max(a[x],b[x])>max(a[y],b[y]);
}
pii tt[SZ];
int bs[SZ];
void eb(int x)
{
	for(;x<SZ;x+=x&-x) bs[x]^=1;
}
int qb(int x)
{
	int s=0;
	for(;x>=1;x-=x&-x)
		s^=bs[x];
	return s;
}
int qb(int l,int r)
{
	return qb(r)^qb(l-1);
}
pii sg[SZ];
pii operator + (pii a,pii b)
{
	return pii(min(a.fi,b.fi),
	max(a.se,b.se));
}
const int M=1048576;
pii qry(int l,int r)
{
	pii aa(2e9,-2e9);
	if(l>r) return aa;
	for(l+=M-1,r+=M+1;l^r^1;l>>=1,r>>=1)
	{
		if(~l&1) aa=aa+sg[l^1];
		if(r&1) aa=aa+sg[r^1];
	}
	return aa;
}
int main()
{
	for(int i=0;i<SZ;++i)
		sg[i]=pii(2e9,-2e9);
//	n=1000,k=1000;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)
//		a[i]=rand()*22768+rand(),
//		b[i]=rand()*22768+rand(),
		scanf("%d%d",a+i,b+i),
		ls[++ln]=a[i],
		ls[++ln]=b[i],
		A[i]=a[i],
		B[i]=b[i];
	for(int i=1;i<=k;++i)
//		t[i]=rand()*22768+rand(),
		scanf("%d",t+i),
		ls[++ln]=t[i];
	sort(ls+1,ls+1+ln);
	#define LS(w) (w=lower_bound(ls+1,ls+1+ln,w)-ls)
	for(int i=1;i<=n;++i)
		LS(a[i]),LS(b[i]);
	for(int i=1;i<=k;++i)
		LS(t[i]);
	ll ans=0;
	for(int i=1;i<=n;++i) id[i]=i;
	sort(id+1,id+1+n,cmp);
	for(int i=1;i<=k;++i)
		tt[i]=pii(t[i],i);
	sort(tt+1,tt+1+k);
	for(int i=1;i<=k;++i)
	{
		int w=t[i]+M; pii v(i,i);
		sg[w]=sg[w]+v;
	}
	for(int i=M-1;i>=1;--i)
		sg[i]=sg[i+i]+sg[i+i+1];
	int u=k;
	for(int uu=1;uu<=n;++uu)
	{
		int i=id[uu],
		mi=min(a[i],b[i]),
		mx=max(a[i],b[i]),
		c=(a[i]==mi),f=c;
		while(u&&tt[u].fi>=mx)
			eb(tt[u--].se);
		pii s=qry(mi,mx-1);
		if(s.fi>s.se)
			f^=qb(1,k);
		else
			f=qb(s.se+1,k);
		if(f) ans+=min(A[i],B[i]);
		else ans+=max(A[i],B[i]);
	}
	printf("%lld\n",ans);
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:80:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
fortune_telling2.cpp:87:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",a+i,b+i),
   ~~~~~~~~~~~~~~~~~~~~~~~
   ls[++ln]=a[i],
   ~~~~~~~~~~~~~~~
   ls[++ln]=b[i],
   ~~~~~~~~~~~~~~~
   A[i]=a[i],
   ~~~~~~~~~^~
   B[i]=b[i];
   ~~~~~~~~~ 
fortune_telling2.cpp:91:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",t+i),
   ~~~~~~~~~~~~~~~^~
   ls[++ln]=t[i];
   ~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 18040 KB Output is correct
2 Correct 21 ms 18040 KB Output is correct
3 Correct 21 ms 18040 KB Output is correct
4 Correct 21 ms 18040 KB Output is correct
5 Correct 21 ms 18040 KB Output is correct
6 Correct 21 ms 18040 KB Output is correct
7 Correct 21 ms 18040 KB Output is correct
8 Correct 21 ms 18040 KB Output is correct
9 Correct 21 ms 17912 KB Output is correct
10 Correct 22 ms 18040 KB Output is correct
11 Correct 22 ms 18168 KB Output is correct
12 Correct 21 ms 18040 KB Output is correct
13 Correct 21 ms 18040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 18040 KB Output is correct
2 Correct 21 ms 18040 KB Output is correct
3 Correct 21 ms 18040 KB Output is correct
4 Correct 21 ms 18040 KB Output is correct
5 Correct 21 ms 18040 KB Output is correct
6 Correct 21 ms 18040 KB Output is correct
7 Correct 21 ms 18040 KB Output is correct
8 Correct 21 ms 18040 KB Output is correct
9 Correct 21 ms 17912 KB Output is correct
10 Correct 22 ms 18040 KB Output is correct
11 Correct 22 ms 18168 KB Output is correct
12 Correct 21 ms 18040 KB Output is correct
13 Correct 21 ms 18040 KB Output is correct
14 Correct 36 ms 18680 KB Output is correct
15 Correct 54 ms 19448 KB Output is correct
16 Correct 72 ms 19976 KB Output is correct
17 Correct 94 ms 21084 KB Output is correct
18 Correct 91 ms 20956 KB Output is correct
19 Correct 91 ms 20984 KB Output is correct
20 Correct 91 ms 20984 KB Output is correct
21 Correct 92 ms 20984 KB Output is correct
22 Correct 70 ms 20596 KB Output is correct
23 Correct 68 ms 20496 KB Output is correct
24 Correct 70 ms 20600 KB Output is correct
25 Correct 67 ms 20548 KB Output is correct
26 Correct 74 ms 20700 KB Output is correct
27 Correct 85 ms 20984 KB Output is correct
28 Correct 81 ms 20984 KB Output is correct
29 Correct 87 ms 21116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 18040 KB Output is correct
2 Correct 21 ms 18040 KB Output is correct
3 Correct 21 ms 18040 KB Output is correct
4 Correct 21 ms 18040 KB Output is correct
5 Correct 21 ms 18040 KB Output is correct
6 Correct 21 ms 18040 KB Output is correct
7 Correct 21 ms 18040 KB Output is correct
8 Correct 21 ms 18040 KB Output is correct
9 Correct 21 ms 17912 KB Output is correct
10 Correct 22 ms 18040 KB Output is correct
11 Correct 22 ms 18168 KB Output is correct
12 Correct 21 ms 18040 KB Output is correct
13 Correct 21 ms 18040 KB Output is correct
14 Correct 36 ms 18680 KB Output is correct
15 Correct 54 ms 19448 KB Output is correct
16 Correct 72 ms 19976 KB Output is correct
17 Correct 94 ms 21084 KB Output is correct
18 Correct 91 ms 20956 KB Output is correct
19 Correct 91 ms 20984 KB Output is correct
20 Correct 91 ms 20984 KB Output is correct
21 Correct 92 ms 20984 KB Output is correct
22 Correct 70 ms 20596 KB Output is correct
23 Correct 68 ms 20496 KB Output is correct
24 Correct 70 ms 20600 KB Output is correct
25 Correct 67 ms 20548 KB Output is correct
26 Correct 74 ms 20700 KB Output is correct
27 Correct 85 ms 20984 KB Output is correct
28 Correct 81 ms 20984 KB Output is correct
29 Correct 87 ms 21116 KB Output is correct
30 Correct 165 ms 24404 KB Output is correct
31 Correct 225 ms 26232 KB Output is correct
32 Correct 295 ms 28536 KB Output is correct
33 Correct 461 ms 33272 KB Output is correct
34 Correct 134 ms 23772 KB Output is correct
35 Correct 453 ms 33144 KB Output is correct
36 Correct 455 ms 33144 KB Output is correct
37 Correct 454 ms 33260 KB Output is correct
38 Correct 457 ms 33272 KB Output is correct
39 Correct 444 ms 33172 KB Output is correct
40 Correct 419 ms 33096 KB Output is correct
41 Correct 428 ms 33120 KB Output is correct
42 Correct 433 ms 33232 KB Output is correct
43 Correct 272 ms 32172 KB Output is correct
44 Correct 269 ms 32248 KB Output is correct
45 Correct 270 ms 32316 KB Output is correct
46 Correct 290 ms 31280 KB Output is correct
47 Correct 287 ms 31200 KB Output is correct
48 Correct 370 ms 33244 KB Output is correct
49 Correct 376 ms 33272 KB Output is correct