답안 #1067015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067015 2024-08-20T09:40:11 Z Unforgettablepl Dragon 2 (JOI17_dragon2) C++17
100 / 100
568 ms 13532 KB
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<complex>
using namespace std;

const int MN=30000,MQ=100000,BS=15,RQ=300;


typedef complex<long long> point;

long long op(point P1,point P2)
{
  return imag((conj(P1)*P2));
}

namespace std{
  bool operator<(point P1,point P2)
  {
    return op(P1,P2)>0;
  }
};



template<class T> class sumBIT
{
private:
  T *bit;
  int S;
public:
  sumBIT(int S0){
    S=S0;
    bit=(T *)calloc(sizeof(T),1<<S);
  }
  void add(int i,T k){
    int p=i+1;
    while(p<1<<S){
      bit[p]+=k;
      p+=p&-p;
    }
  }
  T sum(int p){
    T ret=0;
    while(p>0){
      ret+=bit[p];
      p-=p&-p;
    }
    return ret;
  }
  T rag(int a,int b){
    return sum(b)-sum(a);
  }
};


int main()
{
  int n,m;
  scanf("%d%d",&n,&m);
  static point P[MN];
  static int C[MN];
  for(int i=0;i<n;i++){
    long long x,y;
    scanf("%lld%lld%d",&x,&y,C+i);
    P[i]=point(x,y);
    C[i]--;
  }
  long long d1,e1,d2,e2;
  scanf("%lld%lld%lld%lld",&d1,&e1,&d2,&e2);
  point X=point(d1,e1),Y=point(d2,e2);
  static bool F[MN];
  for(int i=0;i<n;i++){
    F[i]=(op(Y-X,P[i]-X)>0);
  }
  static point A[MN];
  static pair<int,point> AA[MN];
  for(int i=0;i<n;i++){
    A[i]=(F[i]?P[i]-Y:Y-P[i]);
    AA[i]=make_pair(C[i],A[i]);
  }
  sort(AA,AA+n);
  static int D[MN];
  for(int i=0;i<n;i++){
    D[i]=lower_bound(AA,AA+n,make_pair(C[i],A[i]))-AA;
  }
  static int T[MN+1];
  for(int i=0;i<=m;i++){
    T[i]=lower_bound(AA,AA+n,make_pair(i,Y-X))-AA;
  }
  static pair<point,int> Pr[MN];
  for(int i=0;i<n;i++){
    Pr[i]=make_pair(F[i]?P[i]-X:X-P[i],i);
  }
  sort(Pr,Pr+n);
  int Q;
  scanf("%d",&Q);
  static int as[MQ],bs[MQ];
  for(int i=0;i<Q;i++){
    scanf("%d%d",as+i,bs+i);
    as[i]--,bs[i]--;
  }
  static vector<int> V[MN],VN[MN];
  for(int i=0;i<Q;i++){
    V[as[i]].push_back(bs[i]);
    VN[as[i]].push_back(i);
  }
  static vector<int> V2[MN],VN2[MN];
  for(int i=0;i<Q;i++){
    if(V[as[i]].size()>=RQ){
      V2[bs[i]].push_back(as[i]);
      VN2[bs[i]].push_back(i);
    }
  }
  static long long ans[MQ]={0};
  sumBIT<int> seg0(BS),seg1(BS);
  for(int i=0;i<n;i++){
    if(!F[i]){
      seg1.add(D[i],1);
    }
  }
  for(int t=0;t<n;t++){
    int i=Pr[t].second;
    int a=C[i];
    if(F[i]){
      if(V[a].size()<RQ){
	for(int k=0;k<V[a].size();k++){
	  int b=V[a][k],l=VN[a][k];
	  int L=lower_bound(AA,AA+n,make_pair(b,A[i]))-AA;
	  ans[l]+=seg0.rag(L,T[b+1])+seg1.rag(T[b],L);
	}
      }
      seg0.add(D[i],1);
    }
    else{
      if(V[a].size()<RQ){
	for(int k=0;k<V[a].size();k++){
	  int b=V[a][k],l=VN[a][k];
	  int L=lower_bound(AA,AA+n,make_pair(b,A[i]))-AA;
	  ans[l]+=seg0.rag(L,T[b+1])+seg1.rag(T[b],L);
	}
      }
      seg1.add(D[i],-1);
    }
  }
  sumBIT<int> seg2(BS),seg3(BS);
  for(int i=0;i<n;i++){
    seg2.add(D[i],1);
  }
  for(int t=0;t<n;t++){
    int i=Pr[t].second;
    int b=C[i];
    if(F[i]){
      for(int k=0;k<V2[b].size();k++){
	int a=V2[b][k],l=VN2[b][k];
	int L=lower_bound(AA,AA+n,make_pair(a,A[i]))-AA;
	ans[l]+=seg2.rag(T[a],L);
      }
      seg2.add(D[i],-1);
      seg3.add(D[i],1);
    }
    else{
      for(int k=0;k<V2[b].size();k++){
	int a=V2[b][k],l=VN2[b][k];
	int L=lower_bound(AA,AA+n,make_pair(a,A[i]))-AA;
	ans[l]+=seg3.rag(L,T[a+1]);
      }
      seg2.add(D[i],-1);
      seg3.add(D[i],1);
    }
  }
  for(int t=0;t<Q;t++){
    printf("%lld\n",ans[t]);
  }
  return 0;
}

Compilation message

dragon2.cpp: In function 'int main()':
dragon2.cpp:135:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |  for(int k=0;k<V[a].size();k++){
      |              ~^~~~~~~~~~~~
dragon2.cpp:145:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  145 |  for(int k=0;k<V[a].size();k++){
      |              ~^~~~~~~~~~~~
dragon2.cpp:162:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  162 |       for(int k=0;k<V2[b].size();k++){
      |                   ~^~~~~~~~~~~~~
dragon2.cpp:171:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  171 |       for(int k=0;k<V2[b].size();k++){
      |                   ~^~~~~~~~~~~~~
dragon2.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |   scanf("%d%d",&n,&m);
      |   ~~~~~^~~~~~~~~~~~~~
dragon2.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |     scanf("%lld%lld%d",&x,&y,C+i);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |   scanf("%lld%lld%lld%lld",&d1,&e1,&d2,&e2);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dragon2.cpp:105:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |   scanf("%d",&Q);
      |   ~~~~~^~~~~~~~~
dragon2.cpp:108:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |     scanf("%d%d",as+i,bs+i);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5108 KB Output is correct
2 Correct 5 ms 5152 KB Output is correct
3 Correct 17 ms 5340 KB Output is correct
4 Correct 51 ms 7788 KB Output is correct
5 Correct 40 ms 8196 KB Output is correct
6 Correct 5 ms 5152 KB Output is correct
7 Correct 3 ms 5212 KB Output is correct
8 Correct 4 ms 4956 KB Output is correct
9 Correct 4 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 7824 KB Output is correct
2 Correct 38 ms 7608 KB Output is correct
3 Correct 27 ms 7864 KB Output is correct
4 Correct 23 ms 7772 KB Output is correct
5 Correct 21 ms 8020 KB Output is correct
6 Correct 20 ms 7732 KB Output is correct
7 Correct 20 ms 7752 KB Output is correct
8 Correct 22 ms 7508 KB Output is correct
9 Correct 13 ms 7424 KB Output is correct
10 Correct 14 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5108 KB Output is correct
2 Correct 5 ms 5152 KB Output is correct
3 Correct 17 ms 5340 KB Output is correct
4 Correct 51 ms 7788 KB Output is correct
5 Correct 40 ms 8196 KB Output is correct
6 Correct 5 ms 5152 KB Output is correct
7 Correct 3 ms 5212 KB Output is correct
8 Correct 4 ms 4956 KB Output is correct
9 Correct 4 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 21 ms 7824 KB Output is correct
12 Correct 38 ms 7608 KB Output is correct
13 Correct 27 ms 7864 KB Output is correct
14 Correct 23 ms 7772 KB Output is correct
15 Correct 21 ms 8020 KB Output is correct
16 Correct 20 ms 7732 KB Output is correct
17 Correct 20 ms 7752 KB Output is correct
18 Correct 22 ms 7508 KB Output is correct
19 Correct 13 ms 7424 KB Output is correct
20 Correct 14 ms 7516 KB Output is correct
21 Correct 31 ms 7760 KB Output is correct
22 Correct 38 ms 7592 KB Output is correct
23 Correct 234 ms 7984 KB Output is correct
24 Correct 484 ms 10832 KB Output is correct
25 Correct 87 ms 11344 KB Output is correct
26 Correct 62 ms 12112 KB Output is correct
27 Correct 28 ms 9044 KB Output is correct
28 Correct 22 ms 8984 KB Output is correct
29 Correct 55 ms 13392 KB Output is correct
30 Correct 196 ms 11740 KB Output is correct
31 Correct 58 ms 12116 KB Output is correct
32 Correct 61 ms 13500 KB Output is correct
33 Correct 549 ms 11796 KB Output is correct
34 Correct 58 ms 12112 KB Output is correct
35 Correct 59 ms 13532 KB Output is correct
36 Correct 54 ms 11864 KB Output is correct
37 Correct 60 ms 12120 KB Output is correct
38 Correct 207 ms 13136 KB Output is correct
39 Correct 508 ms 12808 KB Output is correct
40 Correct 568 ms 11860 KB Output is correct
41 Correct 60 ms 13136 KB Output is correct
42 Correct 61 ms 13108 KB Output is correct
43 Correct 72 ms 13260 KB Output is correct
44 Correct 27 ms 9048 KB Output is correct
45 Correct 26 ms 9076 KB Output is correct
46 Correct 28 ms 9188 KB Output is correct
47 Correct 25 ms 8932 KB Output is correct
48 Correct 25 ms 9096 KB Output is correct
49 Correct 26 ms 9052 KB Output is correct