Submission #228950

# Submission time Handle Problem Language Result Execution time Memory
228950 2020-05-03T07:15:30 Z Vimmer Kocka (COCI18_kocka) C++14
0 / 70
448 ms 22400 KB
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) ll(x.size())
#define pb push_back
#define N 100005
#define MOD ll(998244353)

using namespace std;

using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;

typedef short int si;

typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ordered_set se;

set <pair <ll, ll> > ser, dob;

ll mx[N], mn[N];

void upd(ll x)
{
    while (sz(ser) > 0 && (*ser.begin()).F <= x)
    {
        se.erase((*ser.begin()).S);

        ser.erase(ser.begin());
    }

    while (sz(dob) > 0 && (*dob.begin()).F <= x)
    {
        se.insert((*dob.begin()).S);

        dob.erase(dob.begin());
    }
}

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n;

    cin >> n;

    ll a[n][4];

    for (ll i = 0; i < n; i++) {cin >> a[i][0]; if (a[i][0] == -1) a[i][0] = n; mx[i] = 1e9; mn[i] = 1e9;}

    for (ll i = 0; i < n; i++) {cin >> a[i][1]; if (a[i][1] == -1) a[i][1] = n;}

    for (ll i = 0; i < n; i++) {cin >> a[i][2]; if (a[i][2] == -1) a[i][2] = n;}

    for (ll i = 0; i < n; i++) {cin >> a[i][3]; if (a[i][3] == -1) a[i][3] = n;}

    ll ans = 0;

    for (ll i = 0; i < n; i++)
    {
        se.insert(i);

        ser.insert({a[i][2] + 1, i});

        dob.insert({max(a[i][2] + 1, ll(n) - a[i][3] + 1), i});

        ans += a[i][2];

        ans += min(ll(n) - a[i][2], a[i][3]);
    }

    for (ll i = 0; i < n; i++)
    {
        upd(i + 1);

        ll l = a[i][0], r = a[i][1];

        r = min(r, ll(n) - l);

        ans += l - se.order_of_key(l);

        ans += r - (sz(se) - se.order_of_key(ll(n) - r));
    }

    for (ll i = 0; i < n; i++)
    {
        if (a[i][2] == n) continue;

        ll x = a[i][2];

        ans++;

        mn[x] = min(mn[x], i);

        mx[x] = min(mx[x], ll(n) - i - 1);

        if (a[i][2] + a[i][3] + 1 != n)
        {
            ll x = n - a[i][3];

            ans++;

            mn[x] = min(mn[x], i);

            mx[x] = min(mx[x], ll(n) - i - 1);
        }
    }

    for (ll i = 0; i < n; i++)
    {
        if (a[i][0] == n) continue;

        if (mn[i] > a[i][0]) ans++;

        if (a[i][0] + a[i][1] + 1 != n)
        {
            if (mx[i] > a[i][1]) ans++;
        }
    }

    if (ans == n * n) cout << "DA" << endl;
      else cout << "NE" << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Incorrect 5 ms 640 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Incorrect 6 ms 512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 334 ms 22264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 448 ms 22400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 331 ms 22264 KB Output isn't correct
2 Halted 0 ms 0 KB -