#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define int long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void phongbeo();
const int mod2=1e9+7;
const int mod1=998244353;
struct ib
{
int a;
int b;
};
struct icd
{
int a,b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
int n,m,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int el=29;
main()
{
//#ifndef ONLINE_JUDGE
// fin(task),fou(task);
//#endif
NHP
//modwwe
// cin>>res;
phongbeo(),down
checktime
}
int bit[200007];
ib a[200007];
ib b[200007];
int d[200007];
int t[800007];
void upd(int x)
{
for(x; x; x-=x&-x)bit[x]++;
}
int get_bit(int x)
{
int ss= 0;
for(x; x<=m; x+=x&-x) ss+=bit[x] ;
return ss%2;
}
void build(int node,int l,int r)
{
if(l==r)
{
t[node]=b[l].b;
return ;
}
int mid=l+r>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
t[node]=max(t[node<<1],t[node<<1|1]);
}
int get(int node,int l,int r,int l1,int r1)
{
if(l>r1||r<l1) return 0;
if(l>=l1&&r<=r1) return t[node];
int mid=l+r>>1;
return max(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1));
}
bool cmp(ib a,ib b)
{
return a.a<b.a;
}
vector<int> v;
vector<int> v2[200007];
ib c[200007];
void phongbeo()
{
cin>>n>>m;
for(int i=1; i<=n; i++)
{
cin>>a[i].a>>a[i].b;
c[i]=a[i];
}
for(int i=1; i<=m; i++)
cin>>b[i].a,b[i].b=i
,v.pb(b[i].a),d[i]=b[i].a;
b[m+1]= {10000000001,m+1};
sort(v.begin(),v.end());
v.pb(10000000001);
sort(b+1,b+2+m,cmp);
build(1,1,m+1);
for(int i=1; i<=m; i++)
d[i]=lower_bound(v.begin(),v.end(), d[i])-v.begin()+1;
for(int i=1; i<=n; i++)
{
if(a[i].a>a[i].b) swap(a[i].a,a[i].b );
s2=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1;
s3=lower_bound(v.begin(),v.end(),a[i].b)-v.begin();
swap(a[i].a,a[i].b);
if(s2>s3) v2[1].pb(i),a[i]=c[i];
else v2[get(1,1,m+1,s2,s3)+1].pb(i);
}
for(int i=m; i>=1; --i)
{
upd(d[i]);
for(auto x:v2[i])
{
s3=lower_bound(v.begin(),v.end(),a[x].a)-v.begin()+1;
s4=get_bit(s3);
if(s4%2==1)swap(a[x].a,a[x].b);
}
}
s2=0;
for(int i=1; i<=n; i++)
s2+=a[i].a;
cout<<s2;
}
Compilation message
fortune_telling2.cpp:39:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
39 | main()
| ^~~~
fortune_telling2.cpp: In function 'void upd(long long int)':
fortune_telling2.cpp:57:9: warning: statement has no effect [-Wunused-value]
57 | for(x; x; x-=x&-x)bit[x]++;
| ^
fortune_telling2.cpp: In function 'long long int get_bit(long long int)':
fortune_telling2.cpp:64:9: warning: statement has no effect [-Wunused-value]
64 | for(x; x<=m; x+=x&-x) ss+=bit[x] ;
| ^
fortune_telling2.cpp: In function 'void build(long long int, long long int, long long int)':
fortune_telling2.cpp:75:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
75 | int mid=l+r>>1;
| ~^~
fortune_telling2.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
fortune_telling2.cpp:85:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
85 | int mid=l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14948 KB |
Output is correct |
2 |
Correct |
4 ms |
14684 KB |
Output is correct |
3 |
Correct |
3 ms |
14684 KB |
Output is correct |
4 |
Correct |
4 ms |
14684 KB |
Output is correct |
5 |
Correct |
4 ms |
14684 KB |
Output is correct |
6 |
Correct |
4 ms |
14684 KB |
Output is correct |
7 |
Correct |
3 ms |
14684 KB |
Output is correct |
8 |
Correct |
3 ms |
14684 KB |
Output is correct |
9 |
Correct |
3 ms |
14896 KB |
Output is correct |
10 |
Correct |
3 ms |
14684 KB |
Output is correct |
11 |
Correct |
4 ms |
14872 KB |
Output is correct |
12 |
Correct |
3 ms |
14684 KB |
Output is correct |
13 |
Correct |
5 ms |
14840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14948 KB |
Output is correct |
2 |
Correct |
4 ms |
14684 KB |
Output is correct |
3 |
Correct |
3 ms |
14684 KB |
Output is correct |
4 |
Correct |
4 ms |
14684 KB |
Output is correct |
5 |
Correct |
4 ms |
14684 KB |
Output is correct |
6 |
Correct |
4 ms |
14684 KB |
Output is correct |
7 |
Correct |
3 ms |
14684 KB |
Output is correct |
8 |
Correct |
3 ms |
14684 KB |
Output is correct |
9 |
Correct |
3 ms |
14896 KB |
Output is correct |
10 |
Correct |
3 ms |
14684 KB |
Output is correct |
11 |
Correct |
4 ms |
14872 KB |
Output is correct |
12 |
Correct |
3 ms |
14684 KB |
Output is correct |
13 |
Correct |
5 ms |
14840 KB |
Output is correct |
14 |
Correct |
12 ms |
15452 KB |
Output is correct |
15 |
Correct |
23 ms |
17884 KB |
Output is correct |
16 |
Correct |
34 ms |
18484 KB |
Output is correct |
17 |
Correct |
43 ms |
20964 KB |
Output is correct |
18 |
Correct |
46 ms |
20944 KB |
Output is correct |
19 |
Correct |
42 ms |
20948 KB |
Output is correct |
20 |
Correct |
43 ms |
20948 KB |
Output is correct |
21 |
Correct |
39 ms |
21204 KB |
Output is correct |
22 |
Correct |
29 ms |
20488 KB |
Output is correct |
23 |
Correct |
31 ms |
20436 KB |
Output is correct |
24 |
Correct |
33 ms |
20492 KB |
Output is correct |
25 |
Correct |
30 ms |
20820 KB |
Output is correct |
26 |
Correct |
36 ms |
20844 KB |
Output is correct |
27 |
Correct |
40 ms |
20960 KB |
Output is correct |
28 |
Correct |
37 ms |
21080 KB |
Output is correct |
29 |
Correct |
41 ms |
20972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14948 KB |
Output is correct |
2 |
Correct |
4 ms |
14684 KB |
Output is correct |
3 |
Correct |
3 ms |
14684 KB |
Output is correct |
4 |
Correct |
4 ms |
14684 KB |
Output is correct |
5 |
Correct |
4 ms |
14684 KB |
Output is correct |
6 |
Correct |
4 ms |
14684 KB |
Output is correct |
7 |
Correct |
3 ms |
14684 KB |
Output is correct |
8 |
Correct |
3 ms |
14684 KB |
Output is correct |
9 |
Correct |
3 ms |
14896 KB |
Output is correct |
10 |
Correct |
3 ms |
14684 KB |
Output is correct |
11 |
Correct |
4 ms |
14872 KB |
Output is correct |
12 |
Correct |
3 ms |
14684 KB |
Output is correct |
13 |
Correct |
5 ms |
14840 KB |
Output is correct |
14 |
Correct |
12 ms |
15452 KB |
Output is correct |
15 |
Correct |
23 ms |
17884 KB |
Output is correct |
16 |
Correct |
34 ms |
18484 KB |
Output is correct |
17 |
Correct |
43 ms |
20964 KB |
Output is correct |
18 |
Correct |
46 ms |
20944 KB |
Output is correct |
19 |
Correct |
42 ms |
20948 KB |
Output is correct |
20 |
Correct |
43 ms |
20948 KB |
Output is correct |
21 |
Correct |
39 ms |
21204 KB |
Output is correct |
22 |
Correct |
29 ms |
20488 KB |
Output is correct |
23 |
Correct |
31 ms |
20436 KB |
Output is correct |
24 |
Correct |
33 ms |
20492 KB |
Output is correct |
25 |
Correct |
30 ms |
20820 KB |
Output is correct |
26 |
Correct |
36 ms |
20844 KB |
Output is correct |
27 |
Correct |
40 ms |
20960 KB |
Output is correct |
28 |
Correct |
37 ms |
21080 KB |
Output is correct |
29 |
Correct |
41 ms |
20972 KB |
Output is correct |
30 |
Correct |
97 ms |
25728 KB |
Output is correct |
31 |
Correct |
133 ms |
28812 KB |
Output is correct |
32 |
Correct |
177 ms |
30408 KB |
Output is correct |
33 |
Correct |
281 ms |
33768 KB |
Output is correct |
34 |
Correct |
90 ms |
25364 KB |
Output is correct |
35 |
Correct |
254 ms |
33804 KB |
Output is correct |
36 |
Correct |
254 ms |
33372 KB |
Output is correct |
37 |
Correct |
257 ms |
33456 KB |
Output is correct |
38 |
Correct |
244 ms |
33520 KB |
Output is correct |
39 |
Correct |
273 ms |
33480 KB |
Output is correct |
40 |
Correct |
202 ms |
33220 KB |
Output is correct |
41 |
Correct |
255 ms |
33336 KB |
Output is correct |
42 |
Correct |
246 ms |
33228 KB |
Output is correct |
43 |
Correct |
149 ms |
32848 KB |
Output is correct |
44 |
Correct |
148 ms |
32848 KB |
Output is correct |
45 |
Correct |
153 ms |
33028 KB |
Output is correct |
46 |
Correct |
159 ms |
31640 KB |
Output is correct |
47 |
Correct |
167 ms |
31816 KB |
Output is correct |
48 |
Correct |
213 ms |
33348 KB |
Output is correct |
49 |
Correct |
208 ms |
33896 KB |
Output is correct |