Submission #555512

# Submission time Handle Problem Language Result Execution time Memory
555512 2022-05-01T06:59:09 Z BT21tata Nekameleoni (COCI15_nekameleoni) C++17
42 / 140
3000 ms 832 KB
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define SPEED ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define rall(v) (v).rbegin(),(v).rend()
#define all(v) (v).begin(),(v).end()
#define setp fixed<<setprecision
#define OK cerr<<"OK"<<endl<<flush
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define F first
#define S second
#define y0 jahdakdh
#define y1 jahsadakdakdh
#define endl '\n'
const ll MOD=1e9+7;
const ll mod=(1ll<<31)-1;
const ld eps=1e-8;
using namespace std;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());

int n, Q, k, a[100005], cnt[55];

int main()
{
    SPEED;
    cin>>n>>k>>Q;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    while(Q--)
    {
        int q, p, v;
        cin>>q;
        if(q==1)
        {
            cin>>p>>v;
            a[p]=v;
        }
        else
        {
            int l=1, r=1, num=0, ans=MOD;
            memset(cnt, 0, sizeof(cnt));
            while(r<=n)
            {
                cnt[a[r]]++;
                if(cnt[a[r]]==1) num++;
                if(num==k) ans=min(ans, r-l+1);
                while(cnt[a[l]]>1)
                {
                    cnt[a[l]]--;
                    l++;
                }
                if(num==k) ans=min(ans, r-l+1);
                //cout<<l<<' '<<r<<' '<<num<<' '<<cnt[1]<<' '<<cnt[2]<<' '<<cnt[3]<<endl;
                r++;
            }
            cout<<((ans==MOD)? -1 : ans)<<endl;
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 27 ms 340 KB Output is correct
2 Correct 5 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 340 KB Output is correct
2 Correct 11 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 340 KB Output is correct
2 Correct 14 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1909 ms 532 KB Output is correct
2 Execution timed out 3075 ms 816 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3081 ms 652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3057 ms 620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3083 ms 576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3076 ms 680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3078 ms 832 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3074 ms 712 KB Time limit exceeded
2 Halted 0 ms 0 KB -