Submission #469314

# Submission time Handle Problem Language Result Execution time Memory
469314 2021-08-31T12:12:35 Z ala2 Nekameleoni (COCI15_nekameleoni) C++14
56 / 140
3000 ms 1864 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[1001000];
int v[100];
signed main()
{
    int n,m,k;
    cin>>n>>k>>m;
    for(int i=1-1;i<=n-1;i++)
        cin>>a[i];
    int mn=1e9;
    for(int vv=0;vv<m;vv++)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            int y,z;
            cin>>y>>z;
            a[y-1]=z;

        }
        else
        {  for(int i=0;i<k+1;i++)  v[i]=0;
  //     for(int i=0;i<n;i++) cout<<a[i]<<" ";

            mn=1e9;
            int g=0;
            int j=3e9;
            for(int i=0;i<n;i++)
            {
                if(!v[a[i]])
                    g++;
                    v[a[i]]++;
                if(g==k){
                    j=i;
                    break;
                }
            } mn=min(mn,j+1);
          //  cout<<"                       : "<<mn<<endl;
            if(mn>n)
            {
                cout<<-1<<endl;
                continue;
            }
            int i=0;
            while(i<n&&j<n&&i<=j)
            { //cout<<"    "<<mn;
                i++;
                v[a[i-1]]--;
                if(v[a[i-1]]>0)
                {
                  //  v[a[i]]--;
                    mn=min(mn,j-i+1);
                  //  cout<<"             :" <<mn<<"   "<<i<<"  "<<j<< endl;
                }
                else
                {
                    j++;
                    while(a[j]!=a[i-1]&&j<n-1)
                    {
                        v[a[j]]++;
                        j++;
                    }
                    v[a[j]]++;
                    if(a[j]==a[i-1]){
                     //       cout<<mn<<"    ";
                    mn=min(mn,j-i+1);
                   // cout<< "    "<<mn<<endl;
                  // cout<<"           "<<i<<"   "<<j<<"  "<<mn<<endl;
                    }
                    else
                    {
                    //    cout<<"                   : :  "<<i<<endl;
                        break;
                    }
                }

            }
            cout<<mn<<endl;
        }
    }
}

Compilation message

nekameleoni.cpp: In function 'int main()':
nekameleoni.cpp:33:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   33 |                 if(!v[a[i]])
      |                 ^~
nekameleoni.cpp:35:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   35 |                     v[a[i]]++;
      |                     ^
# Verdict Execution time Memory Grader output
1 Correct 28 ms 304 KB Output is correct
2 Correct 7 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 332 KB Output is correct
2 Correct 11 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 332 KB Output is correct
2 Correct 14 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1889 ms 956 KB Output is correct
2 Correct 2031 ms 1864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3077 ms 1224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3064 ms 1256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3066 ms 1188 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3088 ms 1216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3071 ms 1480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3083 ms 1480 KB Time limit exceeded
2 Halted 0 ms 0 KB -