답안 #892183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892183 2023-12-25T03:40:57 Z tradz Nekameleoni (COCI15_nekameleoni) C++14
42 / 140
200 ms 4956 KB
#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

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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 2520 KB Output is correct
2 Correct 15 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 2536 KB Output is correct
2 Correct 32 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 2548 KB Output is correct
2 Correct 59 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 4952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -