This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |