Submission #51865674


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>  ordered_set;
//member functions : order_of_key(k){no_of_ele < k} find_by_order(k){kth ele}

const ll M = 998244353;
const ll N = 2e5 + 69;
const ll lmax = 2e18;
const ll lmin = -2e18;
//  ... --- ... 
// --------------------------------------------------------------

// --------------------------------------------------------------

void solve()
{    
    ll n, q, curr = 0; cin >> n >> q;
    set<ll> s;
    vector<ll> a(n + 1, lmin);
    while(q--)
    {
        ll x; cin >> x;
        if(s.find(x) == s.end())
        {
            s.insert(x);
        }
        else
        {
            s.erase(x);
        }
        ll z = s.size();
        if(s.find(x) == s.end())
        {
            a[x] += curr;
        }
        else
        {
            if(a[x] == lmin)
                a[x] = -curr;
            else
            {
                a[x] -= curr;
            }
        }
        curr += z;
    }
    for(int i = 1; i <= n; i++)
    {
        if(a[i] == lmin)
            cout << 0 << " ";
        else if(a[i] > 0)
            cout << a[i] << " ";
        else cout << (a[i] + curr) << " ";
    }
    return;
}

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    solve();
    return 0;
}

Submission Info

Submission Time
Task E - Set Add Query
User jeal0uspengu1n
Language C++ 20 (gcc 12.2)
Score 500
Code Size 1664 Byte
Status AC
Exec Time 107 ms
Memory 14216 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 24
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3508 KiB
00_sample_02.txt AC 1 ms 3428 KiB
01_test_01.txt AC 1 ms 3456 KiB
01_test_02.txt AC 8 ms 3468 KiB
01_test_03.txt AC 55 ms 9308 KiB
01_test_04.txt AC 56 ms 9300 KiB
01_test_05.txt AC 60 ms 9456 KiB
01_test_06.txt AC 98 ms 8544 KiB
01_test_07.txt AC 99 ms 8532 KiB
01_test_08.txt AC 99 ms 8604 KiB
01_test_09.txt AC 99 ms 8540 KiB
01_test_10.txt AC 98 ms 8604 KiB
01_test_11.txt AC 99 ms 8916 KiB
01_test_12.txt AC 99 ms 8532 KiB
01_test_13.txt AC 98 ms 8520 KiB
01_test_14.txt AC 99 ms 8568 KiB
01_test_15.txt AC 98 ms 8516 KiB
01_test_16.txt AC 8 ms 3312 KiB
01_test_17.txt AC 10 ms 3420 KiB
01_test_18.txt AC 12 ms 3464 KiB
01_test_19.txt AC 12 ms 3464 KiB
01_test_20.txt AC 13 ms 3396 KiB
01_test_21.txt AC 99 ms 14216 KiB
01_test_22.txt AC 107 ms 14212 KiB