Submission #892183

#TimeUsernameProblemLanguageResultExecution timeMemory
892183tradzNekameleoni (COCI15_nekameleoni)C++14
42 / 140
200 ms4956 KiB
#include <bits/stdc++.h> #define For(i,a,b) for(int i = a; i <= b; i++) #define Ford(i,a,b) for(int i = a; i >= b; i--) #define ll long long #define ii pair<int,int> #define fi first #define se second #define all(v) v.begin(),v.end() #define RRH(v) v.resize(unique(all(v)) - v.begin()) using namespace std; const int N = 1e6+7; const int M = 1e9+7; const ll oo = 3e18; int n, m, k; int a[N]; namespace sub1 { int cnt[N]; int calc() { int ans = M; set<int> s; int j = 1; For(i, 1, k) cnt[i] = 0; For(i, 1, n) { s.insert(a[i]); cnt[a[i]]++; while(s.size() >= k) { if(cnt[a[j]] >= 2) cnt[a[j]]--, j++; else break; } if(s.size() >= k) ans = min(ans, i - j + 1); } return ans; } void solve() { while(m--) { int t; cin >> t; if(t == 2) { int ans = calc(); if(ans == M) ans = -1; cout << ans << '\n'; } else { int x, y; cin >> x >> y; a[x] = y; } } } } int main() { ios::sync_with_stdio(0); cin.tie(0); #define TASK "" if (fopen (".inp", "r")) { freopen (".inp", "r", stdin); freopen (".out", "w", stdout); } if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } cin >> n >> k >> m; For(i, 1, n) cin >> a[i]; if(n <= 5000 && m <= 5000) { sub1 :: solve(); return 0; } return 0; }

Compilation message (stderr)

nekameleoni.cpp: In function 'int sub1::calc()':
nekameleoni.cpp:31:28: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |             while(s.size() >= k) {
      |                   ~~~~~~~~~^~~~
nekameleoni.cpp:35:25: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |             if(s.size() >= k) ans = min(ans, i - j + 1);
      |                ~~~~~~~~~^~~~
nekameleoni.cpp: In function 'int main()':
nekameleoni.cpp:62:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen (".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
nekameleoni.cpp:63:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen (".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
nekameleoni.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nekameleoni.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...