QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#42913#4431. Interesting NumbersVitheonAC ✓16ms7564kbC++143.7kb2022-08-05 09:12:332022-08-05 09:12:35

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-05 09:12:35]
  • 评测
  • 测评结果:AC
  • 用时:16ms
  • 内存:7564kb
  • [2022-08-05 09:12:33]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <cstdlib>
#include <unordered_map>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define mp make_pair
#define lson tr[now].ls
#define rson tr[now].rs
#define pb push_back
#define debug() cout<<"qwq"<<endl
#define mem(i,a) memset(i,a,sizeof(i))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
#define i128 __int128
#define pii pair<int,int>
const db eps=1e-10;
const ll INF = 0x3f3f3f3f;
const int siev =1000000+5;
const int inf = 0x3f3f3f3f;
const int DMAX = 30000 + 100;
const int G=3;
const int invG=332748118;
const double PI=acos(-1.0);
const ll MOD = 998244353;
const ll LMOD = 1000000007;
const int hmod = 202010923;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
template<class T> inline void print(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    int a[20];
    int cnt=0;
    do{
        a[++cnt]=x%10;
        x/=10;
    }while(x>0);
    for(int i=cnt;i>=1;i--){
        putchar(a[i]+'0');
    }
    putchar('\n');
    // puts("");
}
template<class T> inline void read(T &x){
    x=0;
    T f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-'){
            f=-1;
        }
        ch=getchar();
    }
    while(ch<='9' && ch>='0'){
        x=x*10+(ch-'0');
        ch=getchar();
    }
    x*=f;
}
struct Trie{
    struct node{
        int ch[2];
        int hve;
    };
    node nde[DMAX*30];
    int cnt,rt;
    void clear(){
        for(int i=1;i<=1;i++){
            nde[i].ch[0]=nde[i].ch[1]=nde[i].hve=0;
        }
        cnt=1,rt=1;
    }
    void insert(int val){
        int now=rt;
        nde[now].hve++;
        for(int i=20;i>=0;i--){
            int x=((val>>i) & 1);
            if(!nde[now].ch[x]){
                nde[now].ch[x]=++cnt;
                nde[cnt].hve=0;
                nde[cnt].ch[0]=nde[cnt].ch[1]=0;
            }
            now=nde[now].ch[x];
            nde[now].hve++;
        }
        
    }
    int DFS(int x,int y,int tms,int val){
        // cout<<x<<" "<<y<<" "<<tms<<endl;
        if(!x || !y){
            return nde[x|y].hve;
        }
        if(tms==-1){
            if(x==y){
                return nde[x].hve;  
            }
            return nde[x].hve+nde[y].hve;
        }
        int pos=((val>>tms) & 1);
        if(pos==1){
            int red=0;
            red+=DFS(nde[x].ch[0],nde[y].ch[1],tms-1,val);
            if(x!=y){
                red+=DFS(nde[x].ch[1],nde[y].ch[0],tms-1,val);
            }
            return red;
        }
        if(pos==0){
            int red=0;
            red=max(red,DFS(nde[x].ch[0],nde[y].ch[0],tms-1,val));
            red=max(red,DFS(nde[x].ch[1],nde[y].ch[1],tms-1,val));
        //    int red=max(DFS(nde[x].ch[0],nde[y].ch[0],tms-1,val),DFS(nde[x].ch[1],nde[y].ch[1],tms-1,val));
            if(x!=y){
                red=max(red,max(nde[x].hve,nde[y].hve));
            }
            return red;
        }   
        
    }
};
Trie tr;
int T;
int n,k;
int main(){
    read(T);
    while(T--){
        read(n),read(k);
        tr.clear();
        int x;
        for(int i=1;i<=n;i++){
            read(x);
            tr.insert(x);
        }
        int ans=tr.DFS(1,1,20,k);
        print(ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 16ms
memory: 7564kb

input:

6
30000 887788
295744 887428 33604 327716 100488 363104 299908 329892 100808 34952 557256 100996 821280 334560 68216 854944 297148 960 362788 68096 622628 625250 788548 360737 328264 524932 592672 361026 8780 164004 327808 262656 297024 624772 98376 395652 263052 524404 224 623244 344616 622944 2976...

output:

19915
18057
25682
14945
15025
3880

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 12ms
memory: 5420kb

input:

203
200 83
451 494 342 47 98 470 991 145 83 626 484 517 377 169 388 754 386 651 620 637 565 827 559 214 591 315 113 754 405 307 72 699 674 399 369 19 1009 42 932 349 737 286 834 391 982 647 927 515 840 110 239 454 350 775 457 728 290 78 610 890 51 127 410 316 957 571 180 803 383 308 335 738 281 921 ...

output:

24
21
12
54
105
66
33
19
112
36
12
13
12
56
63
101
20
19
100
19
136
30
24
11
62
59
23
16
18
36
59
17
17
18
33
120
34
15
18
17
32
14
56
14
32
103
55
123
57
11
11
37
30
19
20
60
30
110
64
14
11
36
12
109
20
55
106
24
44
56
55
33
19
36
120
102
34
20
64
112
19
11
21
12
134
39
10
11
65
34
100
110
12
52
1...

result:

ok 203 lines

Test #3:

score: 0
Accepted
time: 5ms
memory: 3660kb

input:

1000
20 20
451 494 342 47 98 470 991 145 83 626 484 517 377 169 388 754 386 651 620 637
20 99
203 85 581 483 268 875 150 167 84 678 371 799 409 531 552 987 604 6 791 609
20 169
391 982 647 927 515 840 110 239 454 350 775 457 728 290 78 610 890 51 127 410
20 83
798 759 347 702 842 251 936 193 359 784...

output:

2
3
4
4
5
3
2
5
2
5
1
2
10
19
3
4
2
4
3
1
7
3
2
4
2
14
1
3
6
2
6
2
1
6
9
2
7
2
5
6
2
3
3
6
11
5
1
8
7
2
5
2
10
4
1
13
5
12
3
4
17
12
5
3
2
3
6
5
4
3
4
2
3
4
7
3
3
2
11
2
6
1
4
5
8
2
6
2
3
3
9
18
6
11
2
7
9
7
2
3
3
5
2
3
10
5
14
4
2
1
2
14
9
2
7
2
3
2
11
4
7
6
2
2
2
7
8
2
7
3
2
11
3
2
3
2
1
2
12
4
2
...

result:

ok 1000 lines

Extra Test:

score: 0
Extra Test Passed