QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#343774#1817. AND PermutationLaStataleBlueWA 2ms3996kbC++234.2kb2024-03-03 01:21:122024-03-03 01:21:12

Judging History

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

  • [2024-03-03 01:21:12]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3996kb
  • [2024-03-03 01:21:12]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double db;

#define TESTCASE 0

static void solve([[maybe_unused]] int tc) {
    int n;
    cin >> n;
    vector<long long> a(n);
    
    for (int i = 0; i < n; i++)cin >> a[i];
    
    /*
    set<int> ds;
    vector<long long> a;
    
    for(int i=0;i<5;i++){
        int x=rand()%128;
        for(int j=0;j<128;j++)if((x&j)==j)ds.insert(j);
    }
    for(auto i : ds)a.push_back(i);
    int n=a.size();
    
    cout<<n<<"\n";
    for(auto i : a)cout<<i<<" ";
    cout<<"\n";*/
    
    if (n == 1) {
        cout << "0\n";
        return;
    }
    
    auto solve = [&](auto &solve, int pos, vector<long long> v) -> map<long long, long long> {
        if (v.size() == 0) {
            return map<long long, long long>();
        }
        if (v.size() == 2) {
            return map<long long, long long>{{v[0], v[1]},
                {v[1], v[0]}};
        }
        if (v.size() == 1) {
            return map<long long, long long>{{v[0], v[0]}};
        }
        
        //cout<<pos<<" bit\n";
        //for(auto i : v)cout<<i<<" ";
        //cout<<"\n";
        
        map<long long, long long> res;
        
        vector<long long> v0, v1;
        for (auto i: v) {
            if (i & (1ll << pos))v1.push_back(i);
            else v0.push_back(i);
        }
        
        map<long long, long long> sol0, sol1;
        sol0 = solve(solve, pos - 1, v0);
        sol1 = solve(solve, pos - 1, v1);
        
        map<long long, int> col;
        auto dfs = [&](auto &dfs, long long pos, int mode) -> void {
            //cout << pos << " dfs\n";
            if (col.find(pos) != col.end())return;
            col[pos] = mode;
            
            dfs(dfs, sol1[pos], mode ^ 1);
            
            if (sol0.find(pos ^ (1ll << pos)) != sol0.end())
                if (sol1.find(sol0[pos ^ (1ll << pos)] ^ (1ll << pos)) != sol1.end()) {
                dfs(dfs, sol0[pos ^ (1ll << pos)] ^ (1ll << pos), mode ^ 1);
            }
        };
        
        int loop0 = -1, loop1 = -1;
        int cont0=0;
        int cont1=0;
        
        for (auto [i, j]: sol0) {
            if (i == j)loop0 = i,cont0++;
        }
        for (auto [i, j]: sol1) {
            if (i == j)loop1 = i,cont1++;
        }
        assert(cont0<=1 && cont1<=1);
        
        
        if(loop1!=-1 && loop0==-1)dfs(dfs,loop1,1);
        if(loop0!=-1 && loop1==-1 && sol1.find(loop0^(1ll<<pos))!=sol1.end())dfs(dfs,loop0^(1ll<<pos),0);
        for (auto i: v1)if (sol1[i] != i)dfs(dfs, i, 1);
        
        
        if (loop0 != -1 && loop1 != -1) {
            assert((loop0^(1<<pos))==loop1);
            assert(col[loop1]==0);
            sol0[loop0] = loop1;
            sol1[loop1] = loop0;
            loop0 = -1;
            loop1 = -1;
        }
        
        for (auto [i, j]: sol1) {
            if (col[i] == 1) {
                if(i==j){
                    int a=i^(1ll<<pos);
                    int b=sol0[a];
                    
                    sol1[i]=b;
                    sol0[b]=i;
                    sol0[a]=a;
                    continue;
                }
                int a = i ^ (1ll << pos);
                int b = sol0[a];
                assert(a!=b);
                
                sol1[i] = b;
                sol1[j] = a;
                sol0[a] = j;
                sol0[b] = i;
            }
        }
        
        
        for (auto [i, j]: sol0)res[i] = j;
        for (auto [i, j]: sol1)res[i] = j;
        
        int cont=0;
        for(auto [i,j] : res)if(i==j)cont++;
        assert(cont<=1);
        
        return res;
    };    
    auto sol = solve(solve, 59, a);
    
    for (int i = 0; i < n; i++) {
        cout << sol[a[i]] << "\n";
        //assert((a[i]&sol[a[i]])==0);
    }
}

int main() {
    //ios::sync_with_stdio(false);
    
    if (const char *f = getenv("REDIRECT_STDOUT"); f) {
        freopen(f, "w", stdout);
    }
    
    srand(42);
    int T = 1;
#if TESTCASE
    cin >> T;
#endif
    
    for (int t = 1; t <= T; t++) {
        solve(t);
    }
    
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3556kb

input:

6
0
1
4
5
2
6

output:

4
6
0
2
5
1

result:

ok OK!

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3996kb

input:

272
315
138
126
6
394
297
44
273
84
200
9
197
396
133
16
46
65
87
86
336
316
174
140
162
250
306
52
188
57
36
63
192
320
388
10
156
15
208
38
32
31
228
30
305
234
384
220
142
72
27
337
110
94
317
304
242
398
209
5
323
29
284
301
309
244
230
261
61
254
266
194
296
275
313
80
206
214
88
308
18
288
106...

output:

196
309
129
248
116
22
210
238
131
55
310
122
114
90
199
209
318
384
137
135
194
337
307
285
4
141
267
3
390
218
256
190
151
280
149
98
112
47
281
287
288
283
224
142
277
87
35
305
182
292
174
144
160
66
206
261
49
46
314
20
290
226
82
138
138
152
242
386
321
132
316
215
204
70
303
304
257
39
11
236...

result:

wrong answer Bit and of corresponding values not zero.