# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
333060 | CaroLinda | Examination (JOI19_examination) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug printf
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x.size() )
#define ll long long
const int MAXN = 4e5+10 ;
using namespace std ;
using namespace __gnu_pbds ;
#define ordered_set tree< pair<int,int> , null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update>
struct Seg
{
ordered_set tree[MAXN*4] ;
int m(int l, int r) { return (l+r)>>1 ; }
void upd(int pos, int l, int r, int aValue, int bValue , int idValue )
{
tree[pos].insert( make_pair(bValue, idValue) ) ;
if(l == r) return ;
if( aValue <= m(l,r) ) upd(pos<<1 , l, m(l,r) , aValue, bValue , idValue ) ;
else upd(pos<<1|1 , m(l,r)+1, r, aValue, bValue, idValue ) ;
}
int qry(int pos, int l, int r, int aValue, int bValue)
{
if(r < aValue ) return 0 ;
if( l >= aValue ) return sz(tree[pos]) - tree[pos].order_of_key(make_pair(bValue, 0)) ;
int al = qry(pos<<1 , l , m(l,r) , aValue , bValue ) ;
int ar = qry(pos<<1|1 , m(l,r)+1, r, aValue, bValue ) ;
return al + ar ;
}
} seg ;
int N , Q ;
map<int,int> coordinateCompression ;
int main()
{
scanf("%d %d", &N, &Q ) ;
vector< pair<int,int> > sweep ;
vector< pair<int,int> > student(N+1) ;
vector< pair<int,int> > queries(Q+1) ;
vector<int> ansQueries(Q+1,0) ;
for(int i = 1 ; i <= N ; i++ )
{
scanf("%d %d", &student[i].first, &student[i].second ) ;
coordinateCompression[ student[i].first ] = 0 ;
coordinateCompression[ student[i].second ] = 0 ;
sweep.push_back( make_pair(student[i].first + student[i].second , i) ) ;
}
for(int i = 1 , C ; i <= Q ; i++ )
{
scanf("%d %d %d", &queries[i].first ,&queries[i].second, &C ) ;
coordinateCompression[ queries[i].first ] = 0 ;
coordinateCompression[ queries[i].second ] = 0 ;
sweep.push_back( make_pair(C, -i ) );
}
int Key = 0 ;
for(auto &e : coordinateCompression ) e.second = ++Key ;
sort(all(sweep) ) ;
for(int i = sz(sweep)-1 ; i >= 0 ; i-- )
{
auto e = sweep[i] ;
if( e.second > 0 )
{
int A = student[ e.second ].first ;
int B = student[ e.second ].second ;
A = coordinateCompression[A] ;
B = coordinateCompression[B] ;
seg.upd(1, 1, Key , A , B, e.second ) ;
}
else
{
int idQuery = -e.second ;
int A = queries[idQuery].first ;
int B = queries[idQuery].second ;
A = coordinateCompression[A] ;
B = coordinateCompression[B] ;
ansQueries[idQuery] = seg.qry(1,1,Key, A, B ) ;
}
}
for(int i = 1 ; i <= Q ; i++ ) printf("%d\n" , ansQueries[i]) ;
}