Submission #412906

# Submission time Handle Problem Language Result Execution time Memory
412906 2021-05-27T18:57:10 Z JerryLiu06 Deda (COCI17_deda) C++17
40 / 140
1000 ms 8688 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using db = long double;
using str = string;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define mp make_pair
#define f first
#define s second

#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)

const int MOD = 1e9 + 7;
const int MX = 2e5 + 10;
const ll INF = 1e18;

int N, Q, P[MX]; int tree[4 * MX];

void update(int x, int l, int r, int pos, int val) { int mid = (l + r) / 2;
    if (l > pos || r < pos) return ; if (l == r) { tree[x] = val; return ; }

    update(2 * x, l, mid, pos, val); update(2 * x + 1, mid + 1, r, pos, val);

    tree[x] = min(tree[2 * x], tree[2 * x + 1]);
}
int query(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2;
    if (l > tr || r < tl) return MOD; if (tl <= l && r <= tr) return tree[x];

    return min(query(2 * x, l, mid, tl, tr), query(2 * x + 1, mid + 1, r, tl, tr));
}
int first(int tl, int tr, int val) { int mid = (tl + tr) / 2;
    if (tl == tr) { if (P[tl] <= val) return tl; return -1; }
    
    if (query(1, 1, N, tl, mid) <= val) return first(tl, mid, val);

    if (query(1, 1, N, mid + 1, tr) <= val) return first(mid + 1, tr, val); return -1;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> N >> Q; FOR(i, 1, 4 * MX) tree[i] = MOD;
    
    F0R(i, Q) {
        char C; int A, B; cin >> C >> A >> B;

        if (C == 'M') update(1, 1, N, B, A), P[B] = A; else cout << first(B, N, A) << "\n";
    }
}

Compilation message

deda.cpp: In function 'void update(int, int, int, int, int)':
deda.cpp:51:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   51 |     if (l > pos || r < pos) return ; if (l == r) { tree[x] = val; return ; }
      |     ^~
deda.cpp:51:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   51 |     if (l > pos || r < pos) return ; if (l == r) { tree[x] = val; return ; }
      |                                      ^~
deda.cpp: In function 'int query(int, int, int, int, int)':
deda.cpp:58:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   58 |     if (l > tr || r < tl) return MOD; if (tl <= l && r <= tr) return tree[x];
      |     ^~
deda.cpp:58:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   58 |     if (l > tr || r < tl) return MOD; if (tl <= l && r <= tr) return tree[x];
      |                                       ^~
deda.cpp: In function 'int first(int, int, int)':
deda.cpp:67:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   67 |     if (query(1, 1, N, mid + 1, tr) <= val) return first(mid + 1, tr, val); return -1;
      |     ^~
deda.cpp:67:77: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   67 |     if (query(1, 1, N, mid + 1, tr) <= val) return first(mid + 1, tr, val); return -1;
      |                                                                             ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Incorrect 3 ms 3404 KB Output isn't correct
3 Incorrect 10 ms 3528 KB Output isn't correct
4 Execution timed out 1091 ms 8320 KB Time limit exceeded
5 Incorrect 806 ms 7832 KB Output isn't correct
6 Correct 957 ms 8216 KB Output is correct
7 Execution timed out 1087 ms 8688 KB Time limit exceeded