Submission #557328

# Submission time Handle Problem Language Result Execution time Memory
557328 2022-05-05T06:55:16 Z pokmui9909 Nekameleoni (COCI15_nekameleoni) C++17
28 / 140
3000 ms 352832 KB
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
using ll = long long;
 
int N, K, Q;
const int INF = 1e9;
struct Node{
    int ans;
    int L[55] = {}, R[55] = {};
    Node(){}
    Node(int _ans){ans = _ans; for(ll i = 0; i < 55; i++) L[i] = INF, R[i] = -INF;}
};
Node f(Node &p, Node &q){
    Node ret(min(p.ans, q.ans));
    for(int i = 1; i <= K; i++){
        ret.L[i] = min(p.L[i], q.L[i]);
        ret.R[i] = max(p.R[i], q.R[i]);
    }
    vector<pair<int, int>> V;
    for(int i = 1; i <= K; i++){
        V.push_back({p.R[i], i});
    }   
    sort(V.begin(), V.end());
    int r = -1;
    for(int i = 0; i + 1 < K; i++){
        if(q.L[V[i].second] == -INF) break;
        r = max(r, q.L[V[i].second]);
        ret.ans = min(ret.ans, r - V[i + 1].first + 1);
    }
    clock_t t2 = clock();
    return ret;
}
Node T[400005];
void update(int n, int s, int e, int k, int v){
    if(s == e){
        T[n] = Node(K == 1 ? 1 : INF);
        T[n].L[v] = T[n].R[v] = k;  
        return;
    }
    int m = (s + e) / 2;
    if(k <= m) update(n * 2, s, m, k, v);
    else update(n * 2 + 1, m + 1, e, k, v);
    T[n] = f(T[n * 2], T[n * 2 + 1]);
}
 
int main(){
    cin.tie(0) -> sync_with_stdio(false);
 
    fill(T, T + 400005, Node(INF));
    cin >> N >> K >> Q;
    for(int i = 1; i <= N; i++){
        int v; cin >> v;
        update(1, 1, N, i, v);
    }
    clock_t t1 = clock();
    while(Q--){
        int op; cin >> op;
        if(op == 1){
            int k, v; cin >> k >> v;
            update(1, 1, N, k, v);
        } else {
            cout << (T[1].ans > N ? -1 : T[1].ans) << '\n';
        }
    }
    clock_t t2 = clock();
    assert((double)(t2 - t1) / CLOCKS_PER_SEC <= 0.12);
}

Compilation message

nekameleoni.cpp: In function 'Node f(Node&, Node&)':
nekameleoni.cpp:31:13: warning: unused variable 't2' [-Wunused-variable]
   31 |     clock_t t2 = clock();
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 168 ms 173992 KB Output is correct
2 Correct 158 ms 174188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 256 ms 174164 KB Output is correct
2 Correct 262 ms 174028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 352 ms 174156 KB Output is correct
2 Runtime error 510 ms 352712 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1950 ms 352832 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3056 ms 174128 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3087 ms 174128 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3075 ms 174216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3077 ms 174248 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3087 ms 173992 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3083 ms 174020 KB Time limit exceeded
2 Halted 0 ms 0 KB -