Submission #253970

# Submission time Handle Problem Language Result Execution time Memory
253970 2020-07-29T07:49:41 Z Vimmer Nekameleoni (COCI15_nekameleoni) C++14
0 / 140
762 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, int tl, int tr)
{
    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;

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

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

    if (bad) f[v] = 0;
     else if (ml != -1 && mr != -1) {f[v] = min(r1 - l1 + 1, r2 - l2 + 1); se.insert(f[v]);}
       else f[v] = 0;

}

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, tl, tr);
}

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, tl, tr);
}
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 9 ms 3712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 4608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 6656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 265 ms 26620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 405 ms 53216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 561 ms 53368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 627 ms 53368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 612 ms 53384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 762 ms 106232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 753 ms 106104 KB Output isn't correct
2 Halted 0 ms 0 KB -