Submission #200900

#TimeUsernameProblemLanguageResultExecution timeMemory
200900SamAndDeda (COCI17_deda)C++17
80 / 140
496 ms65540 KiB
#include <bits/stdc++.h> using namespace std; const int N = 200005, INF = 1000000009; struct ban { char ty; int x, a; }; int n, q; ban b[N]; set<int> t[N * 4]; void ubd(int tl, int tr, int x, int y, int pos) { t[pos].insert(y); if (tl == tr) return; int m = (tl + tr) / 2; if (x <= m) ubd(tl, m, x, y, pos * 2); else ubd(m + 1, tr, x, y, pos * 2 + 1); } int qry(int tl, int tr, int l, int r, int y, int pos) { if (l > r) return INF; if (tl == l && tr == r) { set<int>::iterator it = t[pos].lower_bound(y); if (it != t[pos].end()) return (*it); return INF; } int m = (tl + tr) / 2; return min(qry(tl, m, l, min(m, r), y, pos * 2), qry(m + 1, tr, max(m + 1, l), r, y, pos * 2 + 1)); } int main() { scanf("%d%d", &n, &q); for (int i = 1; i <= q; ++i) { scanf(" %c%d%d", &b[i].ty, &b[i].x, &b[i].a); } int z = 0; vector<int> v; map<int, int> mp; for (int i = 1; i <= q; ++i) v.push_back(b[i].x); sort(v.begin(), v.end()); for (int i = 0; i < v.size(); ++i) { if (!i || v[i] != v[i - 1]) mp[v[i]] = ++z; } for (int i = 1; i <= q; ++i) { b[i].x = mp[b[i].x]; } for (int i = 1; i <= q; ++i) { if (b[i].ty == 'M') { ubd(1, z, b[i].x, b[i].a, 1); } else { int ans = qry(1, z, 1, b[i].x, b[i].a, 1); if (ans == INF) printf("-1\n"); else printf("%d\n", ans); } } return 0; }

Compilation message (stderr)

deda.cpp: In function 'int main()':
deda.cpp:56:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
deda.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~
deda.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c%d%d", &b[i].ty, &b[i].x, &b[i].a);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...