Submission #200901

#TimeUsernameProblemLanguageResultExecution timeMemory
200901SamAndDeda (COCI17_deda)C++17
140 / 140
861 ms52200 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]; int z; vector<int> v; map<int, int> mp; set<int> t[N]; void ubd(int x, int y) { while (x <= z) { t[x].insert(y); x += (x & (-x)); } } int qry(int x, int y) { int ans = INF; set<int>::iterator it; while (x) { it = t[x].lower_bound(y); if (it != t[x].end()) ans = min(ans, (*it)); x -= (x & (-x)); } return ans; } 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); } 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(b[i].x, b[i].a); } else { int ans = qry(b[i].x, b[i].a); if (ans == INF) printf("-1\n"); else printf("%d\n", ans); } } return 0; }

Compilation message (stderr)

deda.cpp: In function 'int main()':
deda.cpp:52:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
deda.cpp:44: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:47: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...