//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/
#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define forr(x,y,z) for(int x = (int)y ; x <= (int)z ; ++x)
#define forn(x,y) for(int x = 1; x <= (int)y; ++x)
#define all(x) (x).begin(),(x).end()
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef unsigned int uint;
typedef complex<ll> point;
const int nmax = 200005;
const ll linf = 1e18;
const ll mod = 1e9+7;
const int inf = 1e9;
int n, k;
vec < pii > asd;
vec < pii > t;
int nx[nmax] , pv[nmax];
int st[4*nmax], bit[nmax];
void uf(int pos , int val){
for(;pos > 0; pos -= pos&-pos){
bit[pos] += val;
}
}
int qf(int pos){
int r = 0;
for(; pos <= k ; pos += pos&-pos){
r += bit[pos];
}
return r;
}
ll rez;
int query(int l , int r , int nod = 1, int lt = 1 , int rt = k+1){
if( lt > r || rt < l || rt < lt) return 0;
if( lt >= l && rt <= r) return st[nod];
int mid = (lt+rt)>>1;
return max(query(l,r,nod*2,lt,mid), query(l,r,nod*2+1,mid+1,rt));
}
void update(int pos , int val , int nod = 1, int lt = 1 , int rt = k+1){
if( lt > pos || rt < pos || lt > rt) return ;
if( lt == rt ){ st[nod] += val; return;}
int mid = (lt+rt)>>1;
update(pos,val,nod*2,lt,mid);
update(pos,val,nod*2+1,mid+1,rt);
st[nod] = max(st[nod*2],st[nod*2+1]);
}
int main(){
fast
cin >> n >> k;
forn(i,n){
int a, b;
cin >> a >> b;
asd.pb({a,b});
}
sort(asd.begin(), asd.end());
forn(i,k){
int as;
cin >> as;
t.pb({as,i});
}
int bl = k-1 , al = k-1;
for(int i = n-1; i >= 0 ;i--){
int a = min(asd[i].fr,asd[i].sc) , b = max(asd[i].fr,asd[i].sc);
while(al >= 0 && t[al].fr >= a){
update(t[al].sc, 1);
al --;
}
while(bl >= 0 && t[bl].fr >= b){
update(t[bl].sc, -1);
uf(t[bl].sc,1);
bl--;
}
int l = 1, r = k+1;
while( l < r){
int mid = (l+r)>>1;
if(query(mid,k+1)>=1){
l = mid + 1;
}else{
r = mid;
}
}
int pos = l - 1;
if(pos == 0){
if(qf(pos)%2){
rez += asd[i].sc;
}else{
rez += asd[i].fr;
}
}else{
if(qf(pos+1)%2){
rez += a;
}else{
rez += b;
}
}
}
cout << rez << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |