Submission details
Task:Permutaatio
Sender:Pikaksi
Submission time:2025-01-18 16:21:02 +0200
Language:C++ (C++20)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.01 s1, 2, 3details
#30.01 s1, 2, 3details
#40.01 s1, 2, 3details
#50.01 s1, 2, 3details
#60.01 s1, 2, 3details
#70.01 s1, 2, 3details
#80.01 s1, 2, 3details
#90.01 s1, 2, 3details
#100.01 s1, 2, 3details
#110.01 s2, 3details
#120.01 s2, 3details
#130.01 s2, 3details
#140.01 s2, 3details
#150.01 s2, 3details
#160.61 s3details
#170.61 s3details
#180.61 s3details
#190.61 s3details
#200.61 s3details
#210.01 s1, 2, 3details
#220.01 s2, 3details
#230.61 s3details

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:127:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |     for (int i = 0; i < sumt.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
input/code.cpp:151:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  151 |     if (n != anst.size()) {
      |         ~~^~~~~~~~~~~~~~

Code

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
// chmod u+x b.sh
void solve(); int main() {
    ios_base::sync_with_stdio(0); cout.tie(0);
    solve();
}

vector<int> t1;
vector<int> t2;
int n;
const int N = 1 << 18;
 

int seg[N * 2];
 
void segset(int val, int loc)
{
    seg[loc + N] = val;
    loc += N;
    for (loc /= 2; loc >= 1; loc /= 2) {
        seg[loc] = max(seg[loc * 2], seg[loc * 2 + 1]);
    }
}
 
int segget(int l, int r)
{
    int ans = 0;
    l += N;
    r += N;
    while (l <= r) {
        if (l % 2 == 1) ans = max(ans, seg[l++]);
        if (r % 2 == 0) ans = max(ans, seg[r--]);
        l /= 2;
        r /= 2;
    }
    return ans;
}

map<int, int> ma;


bool ok(vector<int>& nums, vector<int>& dp1, vector<int>& dp2, vector<int>& l1, vector<int>& l2)
{
    ma.clear();
    //cout << "OK:" << endl;
    for (int i = 0; i < n; i++) {
        ma.insert({nums[i], i});
    }

    for (auto [val, loc] : ma) {
        int ans = segget(0, loc);
        dp1[loc] = ans + 1;
        segset(ans + 1, loc);
    }
    //for (int a : dp1) cout << a << " ";
    
    for (int i = 0; i < 2 * N; i++) {
        seg[i] = 0;
    }

    for (auto [val, loc] : ma) {
        int ans = segget(loc, n - 1);
        dp2[loc] = ans + 1;
        segset(ans + 1, loc);
    }
    //for (int a : dp2) cout << a << " ";
    for (int i = 0; i < n; i++) {
        //assert(dp1[i] != 0);
        //assert(dp2[i] != 0);
        if (dp1[i] != l1[i] || dp2[i] != l2[i]) {
            return false;
        }
    }
    for (int i = 0; i < 2 * N; i++) {
        seg[i] = 0;
    }

    return true;
}
 
void solve()
{
    cin >> n;
    vector<int> testn;
    for (int i = 1; i <= n; i++) testn.push_back(i);
    random_shuffle(testn.begin(), testn.end());
    cout << "tests:\n";
    for (int a : testn) cout << a << " ";
    cout << endl;
    
    vector<int> testt1(n, 0);
    vector<int> testt2(n, 0);
    ok(testn, testt1, testt2, testt1, testt2);
    cout << "test 1:\n";
    for (int a : testt1) cout << a << " ";
    cout << endl;
    cout << "test 2:\n";
    for (int a : testt2) cout << a << " ";
    cout << endl;

    for (int i = 0; i < n; i++) {
        int a;
        //cin >> a;
        a = testt1[i];
        t1.push_back(a);
    }
    for (int i = 0; i < n; i++) {
        int a;
        //cin >> a;
        a = testt2[i];
        t2.push_back(a);
    }

    vector<pair<int, int>> sumt;
    for (int i = 0; i < n; i++) {
        sumt.push_back({t1[i] + t2[i], i});
    }

    sort(sumt.begin(), sumt.end());

    vector<int> anst(n);
    int counter = 1;
    for (int i = 0; i < sumt.size(); i++) {
        anst[sumt[i].second] = counter++;
    }
    vector<int> nums;
    for (int i = 0; i < n; i++) {
        nums.push_back(anst[i]);
    }
    cout << "nums:\n";
    for (int a : nums) cout << a << " ";
    cout << endl;
    vector<int> dp1(n, 0);
    vector<int> dp2(n, 0);
    if (!ok(nums, dp1, dp2, t1, t2)) {

        cout << "dp 1:\n";
        for (int a : dp1) cout << a << " ";
        cout << endl;
        cout << "dp 2:\n";
        for (int a : dp2) cout << a << " ";
        cout << endl;
        
        cout << "IMPOSSIBLE";
        return;
    }
    if (n != anst.size()) {
        while (true) {

        }
    }
    for (int a : anst) cout << a << " ";

}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
1
1
1

correct output

user output
tests:

test 1:

test 2:
...

Test 2

Group: 1, 2, 3

Verdict:

input
2
1 1
1 1

correct output
IMPOSSIBLE

user output
tests:
1 2 
test 1:
1 2 
test 2:
...

Test 3

Group: 1, 2, 3

Verdict:

input
3
1 1 3
3 2 1

correct output
IMPOSSIBLE

user output
tests:
1 3 2 
test 1:
1 2 2 
test 2:
...

Test 4

Group: 1, 2, 3

Verdict:

input
3
1 3 2
2 1 3

correct output
IMPOSSIBLE

user output
tests:
1 3 2 
test 1:
1 2 2 
test 2:
...

Test 5

Group: 1, 2, 3

Verdict:

input
5
1 2 3 4 5
2 1 1 1 1

correct output
IMPOSSIBLE

user output
tests:
5 4 2 3 1 
test 1:
1 1 1 2 1 
test 2:
...

Test 6

Group: 1, 2, 3

Verdict:

input
8
1 2 2 3 2 3 4 5
1 3 2 2 1 1 1 1

correct output
1 8 5 7 2 3 4 6 

user output
tests:
5 4 8 7 1 6 3 2 
test 1:
1 1 2 2 1 2 2 2 
test 2:
...
Truncated

Test 7

Group: 1, 2, 3

Verdict:

input
8
1 2 2 2 1 3 2 1
3 5 4 3 2 3 2 1

correct output
3 8 6 5 2 7 4 1 

user output
tests:
5 4 8 7 1 6 3 2 
test 1:
1 1 2 2 1 2 2 2 
test 2:
...
Truncated

Test 8

Group: 1, 2, 3

Verdict:

input
8
1 2 3 4 5 6 7 8
1 1 1 1 1 1 1 1

correct output
1 2 3 4 5 6 7 8 

user output
tests:
5 4 8 7 1 6 3 2 
test 1:
1 1 2 2 1 2 2 2 
test 2:
...
Truncated

Test 9

Group: 1, 2, 3

Verdict:

input
8
1 1 1 1 1 1 1 1
8 7 6 5 4 3 2 1

correct output
8 7 6 5 4 3 2 1 

user output
tests:
5 4 8 7 1 6 3 2 
test 1:
1 1 2 2 1 2 2 2 
test 2:
...
Truncated

Test 10

Group: 1, 2, 3

Verdict:

input
8
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1

correct output
IMPOSSIBLE

user output
tests:
5 4 8 7 1 6 3 2 
test 1:
1 1 2 2 1 2 2 2 
test 2:
...
Truncated

Test 11

Group: 2, 3

Verdict:

input
500
1 2 2 3 4 4 5 4 6 4 7 8 5 7 9 ...

correct output
25 205 54 76 500 218 316 181 3...

user output
tests:
111 291 12 70 210 469 18 294 1...
Truncated

Test 12

Group: 2, 3

Verdict:

input
500
1 2 3 1 1 2 2 4 1 3 5 3 3 3 4 ...

correct output
336 388 404 309 233 377 240 42...

user output
tests:
111 291 12 70 210 469 18 294 1...
Truncated

Test 13

Group: 2, 3

Verdict:

input
500
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
tests:
111 291 12 70 210 469 18 294 1...
Truncated

Test 14

Group: 2, 3

Verdict:

input
500
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
500 499 498 497 496 495 494 49...

user output
tests:
111 291 12 70 210 469 18 294 1...
Truncated

Test 15

Group: 2, 3

Verdict:

input
500
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
IMPOSSIBLE

user output
tests:
111 291 12 70 210 469 18 294 1...
Truncated

Test 16

Group: 3

Verdict:

input
200000
1 2 2 3 2 1 3 3 2 4 2 3 5 4 5 ...

correct output
12162 165274 130162 168624 391...

user output
tests:
44158 25720 120280 184007 1477...
Truncated

Test 17

Group: 3

Verdict:

input
200000
1 1 2 3 3 2 4 3 4 5 2 5 6 7 3 ...

correct output
191389 13806 133836 173924 159...

user output
tests:
44158 25720 120280 184007 1477...
Truncated

Test 18

Group: 3

Verdict:

input
200000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
tests:
44158 25720 120280 184007 1477...
Truncated

Test 19

Group: 3

Verdict:

input
200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
200000 199999 199998 199997 19...

user output
tests:
44158 25720 120280 184007 1477...
Truncated

Test 20

Group: 3

Verdict:

input
200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
IMPOSSIBLE

user output
tests:
44158 25720 120280 184007 1477...
Truncated

Test 21

Group: 1, 2, 3

Verdict:

input
8
1 1 2 1 2 3 1 3
4 3 3 2 2 3 1 1

correct output
IMPOSSIBLE

user output
tests:
5 4 8 7 1 6 3 2 
test 1:
1 1 2 2 1 2 2 2 
test 2:
...
Truncated

Test 22

Group: 2, 3

Verdict:

input
500
1 2 3 2 1 2 1 2 3 3 3 3 4 1 5 ...

correct output
IMPOSSIBLE

user output
tests:
111 291 12 70 210 469 18 294 1...
Truncated

Test 23

Group: 3

Verdict:

input
200000
1 1 1 2 2 3 1 3 4 1 5 4 2 5 6 ...

correct output
IMPOSSIBLE

user output
tests:
44158 25720 120280 184007 1477...
Truncated