답안 #119243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
119243 2019-06-20T17:43:46 Z KLPP Examination (JOI19_examination) C++14
100 / 100
1647 ms 42500 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long int lld;
typedef pair<lld,lld> pii;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
#define MAX 1000000000
struct query{
  lld A,B,C;
  int index;
};
bool operator<(query a, query b){
  if(a.C<b.C)return true;
  return false;
}
class FT{
  int arr[300000];
  int n;
public:
  void init(int N){
    n=N;
    rep(i,0,n+1)arr[i]=0;
  }
  void update(int pos, int val){
    for(int i=pos;i<=n;i+=(i&(-i))){
      arr[i]+=val;
    }
  }
  int query(int pos){
    int ans=0;
    for(int i=pos;i>0;i-=(i&(-i))){
      ans+=arr[i];
    }
    return ans;
  }
};
class ANS{
  pii points[100000];
  pair<pii,int> queries[100000];
  int n,q;
  vector<int> A,B;
  int respostas[100000];
public:
  void init(int N,int Q,pii A[], pii B[]){
    n=N;
    rep(i,0,n){
      points[i]=A[i];
    }
    q=Q;
    rep(i,0,q){
      queries[i]=pair<pii,int>(B[i],i);
    }
  }
  int BSA(lld x){
    int lo,hi;
    lo=0;
    hi=A.size()-1;
    while(hi-lo>0){
      //cout<<lo<<" "<<hi<<endl;
      int mid=(hi+lo)/2;
      if(A[mid]==x)return mid;
      if(A[mid]<x)lo=mid+1;
      else hi=mid-1;
    }
    return lo;
  }
  int BSB(lld x){
    int lo,hi;
    lo=0;
    hi=B.size()-1;
    while(hi-lo>0){
      //cout<<lo<<" "<<hi<<endl;
      int mid=(hi+lo)/2;
      if(B[mid]==x)return mid;
      if(B[mid]<x)lo=mid+1;
      else hi=mid-1;
    }
    return lo;
  }
  void compress(){
    set<int> a,b;
    rep(i,0,n){
      a.insert(points[i].first);
      b.insert(points[i].second);
    }
    rep(i,0,q){
      a.insert(queries[i].first.first);
      b.insert(queries[i].first.second);
    }
    trav(x,a){
      A.push_back(x);
    }
    trav(y,b){
      B.push_back(y);
    }
    //cout<<"A"<<endl;
    rep(i,0,n){
      //cout<<points[i].first<<" "<<points[i].second<<endl;
      points[i].first=BSA(points[i].first)+1;
      points[i].second=BSB(points[i].second)+1;
      //cout<<points[i].first<<" "<<points[i].second<<endl;
    }
    rep(i,0,q){
      queries[i].first.first=BSA(queries[i].first.first)+1;
      queries[i].first.second=BSB(queries[i].first.second)+1;
    }
    sort(points,points+n);
    sort(queries,queries+q);
    FT *F=new FT();
    F->init(B.size());
    int pnt=n-1;
    for(int i=q-1;i>-1;i--){
      while(pnt>=0 && points[pnt].first>=queries[i].first.first){
	F->update(points[pnt].second,+1);
	pnt--;
      }
      respostas[queries[i].second]=n-pnt-1-F->query(queries[i].first.second-1);
    }
  }
  int responder(int q){
    return respostas[q];
  }
  void clear(){
    A.clear();
    B.clear();
  }
};
int main(){
  
  int n,q;
  scanf("%d %d",&n,&q);
  pii arr[n];
  rep(i,0,n){
    scanf("%lld %lld",&arr[i].first,&arr[i].second);
  }
  sort(arr,arr+n);
  query Q[q];
  rep(i,0,q){
    scanf("%lld %lld %lld",&Q[i].A,&Q[i].B,&Q[i].C);
    Q[i].C=max(Q[i].C,Q[i].A+Q[i].B);
    Q[i].index=i;
  }
  ANS *X=new ANS();
  int answer[q];
  rep(i,0,q)answer[i]=0;
  //cout<<"A"<<endl;
  pii A[n];
  pii B[q];
  rep(i,0,n){
    A[i].first=arr[i].first;
    A[i].second=arr[i].first+arr[i].second;
  }
  rep(i,0,q){
    B[i].first=Q[i].A;
    B[i].second=Q[i].C;
  }
  //cout<<"A"<<endl;
  X->init(n,q,A,B);
  //cout<<"A"<<endl;
  X->compress();
  X->clear();
  //cout<<"A"<<endl;
  rep(i,0,q){
    answer[i]+=X->responder(i);
    //cout<<answer[i]<<endl;
  }
  rep(i,0,n){
    A[i].first=arr[i].first;
    A[i].second=arr[i].first+arr[i].second;
  }
  rep(i,0,q){
    B[i].first=Q[i].C-Q[i].B;
    B[i].second=Q[i].C;
  }
  //cout<<"A"<<endl;
  X->init(n,q,A,B);
  //cout<<"A"<<endl;
  X->compress();
  X->clear();
  //cout<<"A"<<endl;
  rep(i,0,q){
    answer[i]-=X->responder(i);
    //cout<<answer[i]<<endl;
  }
  rep(i,0,n){
    A[i].first=arr[i].first;
    A[i].second=arr[i].second;
  }
  rep(i,0,q){
    B[i].first=Q[i].C-Q[i].B;
    B[i].second=Q[i].B;
  }
  //cout<<"A"<<endl;
  X->init(n,q,A,B);
  //cout<<"A"<<endl;
  X->compress();
  X->clear();
  //cout<<"A"<<endl;
  rep(i,0,q){
    answer[i]+=X->responder(i);
    //cout<<answer[i]<<endl;
  }
  rep(i,0,q)printf("%d\n",answer[i]);
  return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:132:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&n,&q);
   ~~~~~^~~~~~~~~~~~~~~
examination.cpp:135:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld",&arr[i].first,&arr[i].second);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:140:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld %lld",&Q[i].A,&Q[i].B,&Q[i].C);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8192 KB Output is correct
2 Correct 8 ms 8192 KB Output is correct
3 Correct 7 ms 8192 KB Output is correct
4 Correct 8 ms 8192 KB Output is correct
5 Correct 8 ms 8192 KB Output is correct
6 Correct 8 ms 8192 KB Output is correct
7 Correct 22 ms 9208 KB Output is correct
8 Correct 23 ms 9208 KB Output is correct
9 Correct 22 ms 9188 KB Output is correct
10 Correct 19 ms 9216 KB Output is correct
11 Correct 18 ms 8960 KB Output is correct
12 Correct 13 ms 8448 KB Output is correct
13 Correct 22 ms 9216 KB Output is correct
14 Correct 23 ms 9208 KB Output is correct
15 Correct 25 ms 9336 KB Output is correct
16 Correct 16 ms 8832 KB Output is correct
17 Correct 20 ms 9208 KB Output is correct
18 Correct 11 ms 8448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 938 ms 27652 KB Output is correct
2 Correct 886 ms 29808 KB Output is correct
3 Correct 898 ms 29724 KB Output is correct
4 Correct 615 ms 27632 KB Output is correct
5 Correct 396 ms 23308 KB Output is correct
6 Correct 147 ms 18044 KB Output is correct
7 Correct 775 ms 28700 KB Output is correct
8 Correct 919 ms 29832 KB Output is correct
9 Correct 601 ms 27380 KB Output is correct
10 Correct 391 ms 23280 KB Output is correct
11 Correct 575 ms 27564 KB Output is correct
12 Correct 122 ms 17616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 938 ms 27652 KB Output is correct
2 Correct 886 ms 29808 KB Output is correct
3 Correct 898 ms 29724 KB Output is correct
4 Correct 615 ms 27632 KB Output is correct
5 Correct 396 ms 23308 KB Output is correct
6 Correct 147 ms 18044 KB Output is correct
7 Correct 775 ms 28700 KB Output is correct
8 Correct 919 ms 29832 KB Output is correct
9 Correct 601 ms 27380 KB Output is correct
10 Correct 391 ms 23280 KB Output is correct
11 Correct 575 ms 27564 KB Output is correct
12 Correct 122 ms 17616 KB Output is correct
13 Correct 1043 ms 31108 KB Output is correct
14 Correct 931 ms 29828 KB Output is correct
15 Correct 973 ms 29776 KB Output is correct
16 Correct 599 ms 27892 KB Output is correct
17 Correct 459 ms 25584 KB Output is correct
18 Correct 143 ms 18012 KB Output is correct
19 Correct 985 ms 31060 KB Output is correct
20 Correct 991 ms 30032 KB Output is correct
21 Correct 942 ms 31572 KB Output is correct
22 Correct 423 ms 23284 KB Output is correct
23 Correct 539 ms 27376 KB Output is correct
24 Correct 118 ms 17656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8192 KB Output is correct
2 Correct 8 ms 8192 KB Output is correct
3 Correct 7 ms 8192 KB Output is correct
4 Correct 8 ms 8192 KB Output is correct
5 Correct 8 ms 8192 KB Output is correct
6 Correct 8 ms 8192 KB Output is correct
7 Correct 22 ms 9208 KB Output is correct
8 Correct 23 ms 9208 KB Output is correct
9 Correct 22 ms 9188 KB Output is correct
10 Correct 19 ms 9216 KB Output is correct
11 Correct 18 ms 8960 KB Output is correct
12 Correct 13 ms 8448 KB Output is correct
13 Correct 22 ms 9216 KB Output is correct
14 Correct 23 ms 9208 KB Output is correct
15 Correct 25 ms 9336 KB Output is correct
16 Correct 16 ms 8832 KB Output is correct
17 Correct 20 ms 9208 KB Output is correct
18 Correct 11 ms 8448 KB Output is correct
19 Correct 938 ms 27652 KB Output is correct
20 Correct 886 ms 29808 KB Output is correct
21 Correct 898 ms 29724 KB Output is correct
22 Correct 615 ms 27632 KB Output is correct
23 Correct 396 ms 23308 KB Output is correct
24 Correct 147 ms 18044 KB Output is correct
25 Correct 775 ms 28700 KB Output is correct
26 Correct 919 ms 29832 KB Output is correct
27 Correct 601 ms 27380 KB Output is correct
28 Correct 391 ms 23280 KB Output is correct
29 Correct 575 ms 27564 KB Output is correct
30 Correct 122 ms 17616 KB Output is correct
31 Correct 1043 ms 31108 KB Output is correct
32 Correct 931 ms 29828 KB Output is correct
33 Correct 973 ms 29776 KB Output is correct
34 Correct 599 ms 27892 KB Output is correct
35 Correct 459 ms 25584 KB Output is correct
36 Correct 143 ms 18012 KB Output is correct
37 Correct 985 ms 31060 KB Output is correct
38 Correct 991 ms 30032 KB Output is correct
39 Correct 942 ms 31572 KB Output is correct
40 Correct 423 ms 23284 KB Output is correct
41 Correct 539 ms 27376 KB Output is correct
42 Correct 118 ms 17656 KB Output is correct
43 Correct 1639 ms 42316 KB Output is correct
44 Correct 1621 ms 42380 KB Output is correct
45 Correct 1647 ms 42268 KB Output is correct
46 Correct 1156 ms 40812 KB Output is correct
47 Correct 834 ms 33260 KB Output is correct
48 Correct 152 ms 17912 KB Output is correct
49 Correct 1518 ms 42332 KB Output is correct
50 Correct 1492 ms 42500 KB Output is correct
51 Correct 1396 ms 42252 KB Output is correct
52 Correct 719 ms 33144 KB Output is correct
53 Correct 1095 ms 39980 KB Output is correct