Submission #557325

# Submission time Handle Problem Language Result Execution time Memory
557325 2022-05-05T06:53:08 Z pokmui9909 Nekameleoni (COCI15_nekameleoni) C++17
Compilation error
0 ms 0 KB
1#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.1);
}

Compilation message

nekameleoni.cpp:1:2: error: stray '#' in program
    1 | 1#include <bits/stdc++.h>
      |  ^
nekameleoni.cpp:1:1: error: expected unqualified-id before numeric constant
    1 | 1#include <bits/stdc++.h>
      | ^
nekameleoni.cpp: In function 'Node f(Node&, Node&)':
nekameleoni.cpp:15:14: error: 'min' was not declared in this scope
   15 |     Node ret(min(p.ans, q.ans));
      |              ^~~
nekameleoni.cpp:18:20: error: 'max' was not declared in this scope
   18 |         ret.R[i] = max(p.R[i], q.R[i]);
      |                    ^~~
nekameleoni.cpp:20:5: error: 'vector' was not declared in this scope
   20 |     vector<pair<int, int>> V;
      |     ^~~~~~
nekameleoni.cpp:3:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    2 | #include <ctime>
  +++ |+#include <vector>
    3 | using namespace std;
nekameleoni.cpp:20:12: error: 'pair' was not declared in this scope
   20 |     vector<pair<int, int>> V;
      |            ^~~~
nekameleoni.cpp:3:1: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
    2 | #include <ctime>
  +++ |+#include <utility>
    3 | using namespace std;
nekameleoni.cpp:20:17: error: expected primary-expression before 'int'
   20 |     vector<pair<int, int>> V;
      |                 ^~~
nekameleoni.cpp:22:9: error: 'V' was not declared in this scope
   22 |         V.push_back({p.R[i], i});
      |         ^
nekameleoni.cpp:24:10: error: 'V' was not declared in this scope
   24 |     sort(V.begin(), V.end());
      |          ^
nekameleoni.cpp:24:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   24 |     sort(V.begin(), V.end());
      |     ^~~~
      |     short
nekameleoni.cpp:28:13: error: 'max' was not declared in this scope
   28 |         r = max(r, q.L[V[i].second]);
      |             ^~~
nekameleoni.cpp:31:13: warning: unused variable 't2' [-Wunused-variable]
   31 |     clock_t t2 = clock();
      |             ^~
nekameleoni.cpp: In function 'int main()':
nekameleoni.cpp:48:5: error: 'cin' was not declared in this scope
   48 |     cin.tie(0) -> sync_with_stdio(false);
      |     ^~~
nekameleoni.cpp:3:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    2 | #include <ctime>
  +++ |+#include <iostream>
    3 | using namespace std;
nekameleoni.cpp:50:5: error: 'fill' was not declared in this scope; did you mean 'll'?
   50 |     fill(T, T + 400005, Node(INF));
      |     ^~~~
      |     ll
nekameleoni.cpp:63:13: error: 'cout' was not declared in this scope
   63 |             cout << (T[1].ans > N ? -1 : T[1].ans) << '\n';
      |             ^~~~
nekameleoni.cpp:63:13: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
nekameleoni.cpp:67:5: error: 'assert' was not declared in this scope
   67 |     assert((double)(t2 - t1) / CLOCKS_PER_SEC <= 0.1);
      |     ^~~~~~
nekameleoni.cpp:3:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
    2 | #include <ctime>
  +++ |+#include <cassert>
    3 | using namespace std;