Submission #253974

# Submission time Handle Problem Language Result Execution time Memory
253974 2020-07-29T08:01:00 Z Vimmer Nekameleoni (COCI15_nekameleoni) C++14
0 / 140
861 ms 106232 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) int(x.size())
#define pb push_back
#define pf push_front
#define N 100050
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef array <ll, 3> a3;
typedef array <ll, 5> a5;

//typedef tree <ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


pair <int, int> t[4 * N][51];

int f[4 * N];

int n, k, m, a[N];

multiset <int> se;

void comb(int v)
{
    if (f[v] != 0) se.erase(se.find(f[v]));

    int l = v + v, r = v + v + 1, ml = -1, mr = -1;

    bool bad = 0;

    for (int i = 1; i <= k; i++)
    {
        t[v][i] = {0, 0};

        if (t[l][i].F != 0) t[v][i].F = t[l][i].F;
          else if (t[r][i].F != 0) t[v][i].F = t[r][i].F;

        if (t[r][i].S != 0) t[v][i].S = t[r][i].S;
          else if (t[l][i].S != 0) t[v][i].S = t[l][i].S;

        if (t[v][i].F == 0) {bad = 1; continue;}

        if (t[l][i].F != 0 && t[r][i].F != 0) continue;

        if (t[l][i].F == 0)
        {
            if (mr == -1) mr = t[r][i].F;
              else mr = max(mr, t[r][i].F);

        }
        else
        {
            if (ml == -1) ml = t[l][i].S;
              else ml = min(ml, t[l][i].S);
        }
    }

    int l1 = mr, r1 = mr, l2 = ml, r2 = ml;

      for (int i = 1; i <= k; i++)
      {
            if (mr != -1 && t[l][i].F != 0 && (t[r][i].F == 0 || t[r][i].F > r1)) l1 = min(l1, t[l][i].S);

            if (ml != -1 && t[r][i].F != 0 && (t[l][i].F == 0 || t[l][i].S < l2)) r2 = max(r2, t[r][i].F);
      }

    int val = 1e9;

    if (mr != -1) val = min(val, r1 - l1 + 1);

    if (ml != -1) val = min(val, r2 - l2 + 1);

    if (bad || val == 1e9) f[v] = 0;
     else {f[v] = val; se.insert(val);}
}

void bld(int v, int tl, int tr)
{
    if (tl == tr)
    {
        t[v][a[tl]] = {tl, tr};

        return;
    }

    int md = (tl + tr) >> 1;

    bld(v + v, tl, md); bld(v + v + 1, md + 1, tr);

    comb(v);
}

void upd(int v, int tl, int tr, int pos, int val)
{
    if (tl == tr)
    {
        t[v][a[tl]] = {0, 0};

        a[tl] = val;

        t[v][a[tl]] = {tl, tr};

        return;
    }

    int md = (tl + tr) >> 1;

    if (pos <= md) upd(v + v, tl, md, pos, val);
     else upd(v + v + 1, md + 1, tr, pos, val);

    comb(v);
}
int main()
{
    //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);

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

    cin >> n >> k >> m;

    for (int i = 1; i <= n; i++) cin >> a[i];

    bld(1, 1, n);

    for (; m > 0; m--)
    {
        int t;

        cin >> t;

        if (t == 1)
        {
            int p, x;

            cin >> p >> x;

            upd(1, 1, n, p, x);

            continue;
        }

        if (k == 1) {cout << 1 << '\n'; continue;}

        if (sz(se) == 0) {cout << "-1" << '\n'; continue;}

        cout << *se.begin() << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 3712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 4608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 6656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 287 ms 26616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 414 ms 53336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 610 ms 53112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 674 ms 53624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 692 ms 53372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 861 ms 106124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 829 ms 106232 KB Output isn't correct
2 Halted 0 ms 0 KB -