Submission #72732141


Source Code Expand

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

using ll=long long;
using ull=unsigned long long;

int getq(ll x, ll y){
    if(y==0){
        if(x>0)return 0;
        return 4;
    }else if(x==0){
        if(y>0)return 2;
        return 6;
    }

    if(x>0){
        if(y>0)return 1;
        return 7;
    }else{
        if(y>0)return 3;
        return 5;
    }
}

bool fcomp(const pair<pair<ll,ll>, int>& A, const pair<pair<ll,ll>, int>& B){
    pair<ll,ll> a=A.first, b=B.first;
    int aq=getq(a.first, a.second), bq=getq(b.first, b.second);

    if(aq!=bq)return aq<bq;

    return a.second*b.first<a.first*b.second;
}

void solve(){
    int N, Q; cin>>N>>Q;
    vector<pair<pair<ll,ll>, int>> XY(N);
    for(int i=0; i<N; ++i){
        ll X, Y; cin>>X>>Y;
        if(X!=0&&Y!=0){
            ll d=gcd(abs(X), abs(Y));
            X/=d; Y/=d;
        }else if(X==0){
            Y/=abs(Y);
        }else if(Y==0){
            X/=abs(X);
        }
        pair<ll,ll> c=make_pair(X, Y);
        XY[i]=make_pair(c, i);
    }

    sort(XY.begin(), XY.end(), fcomp);
    reverse(XY.begin(), XY.end());

    vector<int> A, P(N);
    {
        pair<ll,ll> pre=XY[0].first;
        A.push_back(0);
        A.push_back(1);
        P[XY[0].second]=0;
        for(int i=1; i<N; ++i){
            if(pre.first==XY[i].first.first&&pre.second==XY[i].first.second){
                A.back()++;
            }else{
                A.push_back(1);
                pre=XY[i].first;
            }
            P[XY[i].second]=A.size()-2;
        }
    }
    int M=A.size()-1;
    
    A.resize(M*2+1);
    for(int i=M+1; i<=2*M; ++i)A[i]=A[i-M];
    for(int i=1; i<=2*M; ++i)A[i]+=A[i-1];
    for(;Q--;){
        int a, b; cin>>a>>b;
        cout<<(P[a]<P[b]?A[P[b]+1]-A[P[a]]:A[P[b]+M+1]-A[P[a]])<<endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //cout<<fixed<<setprecision(17);
    int T=1; //cin>>T;
    while(T--)solve();
    return 0;
}

Submission Info

Submission Time
Task E - Laser Takahashi
User Aseteyan
Language C++23 (GCC 15.2.0)
Score 0
Code Size 2070 Byte
Status WA
Exec Time 105 ms
Memory 11300 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 450
Status
WA × 3
WA × 33
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 05_killer_00.txt, 05_killer_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt WA 1 ms 3544 KiB
00_sample_01.txt WA 1 ms 3588 KiB
00_sample_02.txt WA 1 ms 3536 KiB
01_random_00.txt WA 35 ms 5324 KiB
01_random_01.txt WA 88 ms 10936 KiB
01_random_02.txt WA 88 ms 10380 KiB
01_random_03.txt WA 5 ms 3740 KiB
01_random_04.txt WA 93 ms 11172 KiB
01_random_05.txt WA 103 ms 11300 KiB
01_random_06.txt WA 104 ms 11188 KiB
01_random_07.txt WA 103 ms 11152 KiB
01_random_08.txt WA 105 ms 11192 KiB
01_random_09.txt WA 104 ms 11296 KiB
02_random2_00.txt WA 103 ms 11012 KiB
02_random2_01.txt WA 102 ms 10844 KiB
02_random2_02.txt WA 102 ms 10796 KiB
02_random2_03.txt WA 103 ms 10908 KiB
02_random2_04.txt WA 104 ms 10904 KiB
02_random2_05.txt WA 102 ms 10804 KiB
02_random2_06.txt WA 103 ms 10948 KiB
02_random2_07.txt WA 103 ms 10860 KiB
02_random2_08.txt WA 102 ms 10896 KiB
02_random2_09.txt WA 103 ms 10860 KiB
03_random3_00.txt WA 96 ms 10780 KiB
03_random3_01.txt WA 87 ms 10404 KiB
03_random3_02.txt WA 78 ms 9776 KiB
03_random3_03.txt WA 69 ms 9436 KiB
03_random3_04.txt WA 56 ms 8760 KiB
04_handmade_00.txt WA 42 ms 8876 KiB
04_handmade_01.txt WA 43 ms 8720 KiB
04_handmade_02.txt WA 17 ms 3616 KiB
05_killer_00.txt WA 94 ms 10996 KiB
05_killer_01.txt WA 99 ms 11048 KiB