UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#191251#3387. 数对计数Lynkcat1004264ms470016kbC++111.9kb2023-10-08 15:35:202023-10-08 18:34:42

answer

#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define mod 998244353
#define sz(x) ((int)((x).size()))
#define int ll
// #define N 
using namespace std;
const int inf=1e18;
pair<int,pa>all[10000005],all1[10000005];
map<int,int>tot;
int cnt,cnt1;
int n,q;
void BellaKira()
{
    cin>>n>>q;
    for (int i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        int tots=0;
        while (1)
        {
            if (min(x,y)==0) break;
            tots++;
            if (max(x,y)%min(x,y)==0) tot[min(x,y)]++;
            if (x==y)
            {
                break;
            } else
            if (x<y)
            {
                all[++cnt]=mp(x,mp(y%x,y));
                y%=x;
            } else 
                all1[++cnt1]=mp(y,mp(x%y,x)),x%=y;
        }
        // if (i%100==0) 
        //     cerr<<cnt<<" "<<cnt1<<endl;
    }
    sort(all+1,all+cnt+1);
    sort(all1+1,all1+cnt1+1);
    while (q--)
    {
        int ans=0;
        int x,y;
        cin>>x>>y;
        if (x==y)
        {
            ans+=tot[x];
        } else
        if (x<y)
        {
            int l=lower_bound(all+1,all+cnt+1,mp(x,mp(y%x,y)))-all;
            int r=lower_bound(all+1,all+cnt+1,mp(x,mp(y%x,inf)))-all;
            ans+=r-l;
        } else
        {
            int l=lower_bound(all1+1,all1+cnt1+1,mp(y,mp(x%y,x)))-all1;
            int r=lower_bound(all1+1,all1+cnt1+1,mp(y,mp(x%y,inf)))-all1;
            ans+=r-l;
        }
        cout<<ans<<'\n';
    }

}
signed main()
{
    IOS;
    cin.tie(0);
    int T=1;
    while (T--)
    {
        BellaKira();
    }
}
/*list:
1.mod 998244353 or 1e9+7 or ???
2.N
3.duipai shuju xingtai duoyidian
...
*/

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 72ms
memory: 470012kb

input:

5000 5000
7 65
29 55
49 52
20 28
38 46
96 28
23 89
33 6
48 27
77 52
40 22
25 40
45 64
14 51
21 34
67...

output:

2
2
0
0
0
1
90
0
4
0
1
0
1
0
2
13
0
0
0
37
1
0
0
22
1
0
5
1
0
0
4
1
0
1
0
3
2
7
2
0
8
0
0
0
5
1
0
0
...

result:

ok 5000 numbers

Test #2:

score: 10
Accepted
time: 55ms
memory: 470016kb

input:

5000 5000
22 100
48 83
86 76
78 64
22 47
30 78
73 53
95 45
65 6
40 56
32 53
87 69
35 86
38 43
63 4
4...

output:

0
4
96
1
0
1
5
1
1
0
3
1
0
33
0
1
1
27
2
10
0
0
0
1
0
57
0
0
0
0
1
6
0
1
3
0
2
2
6
1
1
1
3
1
7
0
0
1...

result:

ok 5000 numbers

Test #3:

score: 10
Accepted
time: 122ms
memory: 470008kb

input:

4998 4998
543760234006564088 859358949764297134
663315084041950431 419548602848629539
71428077200956...

output:

1
1
1
1
1
1
1
1
3
1
1
1
1
1
1496
1091
14
1
1
1
1
1
1
1
1
1
1
1
1
1
790
443
1
1
1
1
1
1
1
1
1
1
1
6
1...

result:

ok 4998 numbers

Test #4:

score: 10
Accepted
time: 63ms
memory: 470012kb

input:

4999 4998
347560946017710867 891280337760285753
774463175891313963 449326859767449111
47657186921100...

output:

1
8
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
13
1
1
1
1091
1
1
1
1
1
486
59
1
1674
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 4998 numbers

Test #5:

score: 10
Accepted
time: 79ms
memory: 470012kb

input:

4999 5000
738005852911566441 455253942210235041
902599850586507639 349872051751149951
70041874328787...

output:

1
4
1
334
1
1
1
94
3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
4
1
1
1
1
1
1
1
1...

result:

ok 5000 numbers

Test #6:

score: 10
Accepted
time: 113ms
memory: 470012kb

input:

100000 100000
1 23541507
1 2521791386
1 1978086739
1 1630335866
1 3451751650
1 2754027416
1 13352213...

output:

47301
38057
99236
72459
64557
36580
98300
60242
95563
43458
599
93482
75829
68803
25641
49081
71658
...

result:

ok 100000 numbers

Test #7:

score: 10
Accepted
time: 105ms
memory: 470008kb

input:

99999 99998
1 781343450
1 2402276445
1 4021394374
1 337863610
1 1868329968
1 1463431940
1 3387093902...

output:

75483
53381
73185
66547
92070
86097
92151
5882
50454
78184
55390
35938
59481
93845
96094
88403
32474...

result:

ok 99998 numbers

Test #8:

score: 10
Accepted
time: 1157ms
memory: 470008kb

input:

99999 100000
601556870046421826 973337930584775364
889417460882491203 549733719578298264
63024900440...

output:

1
1
1
261
947
721
1
291
43
1
1
19136
528
1
30195
1
1
242
2
1
1
1138
1
217
19072
909
311
1
1
1
1
821
...

result:

ok 100000 numbers

Test #9:

score: 10
Accepted
time: 1326ms
memory: 470008kb

input:

99999 99998
959935367184636831 556934080579014453
880067644875578859 336155927943398900
465036150885...

output:

14
4
1
1135
1
8879
1
76
236
2
24933
4
4435
18
6
1
1
1
513
1
1
542
503
9525
21867
1
34
756
1
2
39
35
...

result:

ok 99998 numbers

Test #10:

score: 10
Accepted
time: 1172ms
memory: 470008kb

input:

99999 100000
656632421007465234 400206357551557618
828463774400365683 512016662099474415
86638605990...

output:

1
1
720
97
433
1
189
1
19331
28284
28
13919
36
706
28249
903
56
2
1
20
1
29
18119
1
6429
2
17035
265...

result:

ok 100000 numbers