Submission #620173

#TimeUsernameProblemLanguageResultExecution timeMemory
620173stevancvExamination (JOI19_examination)C++14
0 / 100
240 ms17504 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 6e5 + 2; const int mod = 1e9 + 7; struct fenwick { int bit[N]; void Add(int x, int y) { for (; x < N; x += x & (-x)) bit[x] += y; } int Get(int x) { x -= 1; int ans = 0; for (; x > 0; x -= x & (-x)) ans += bit[x]; return ans; } }f1, f2; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; vector<array<int, 4>> all; vector<int> vals; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; all.push_back({a, b, a + b, -1}); vals.push_back(a); vals.push_back(b); vals.push_back(a + b); } for (int i = 0; i < q; i++) { int a, b, c; cin >> a >> b >> c; smax(c, a + b); all.push_back({a, b, c, i}); vals.push_back(a); vals.push_back(b); vals.push_back(c); } sort(all.begin(), all.end(), [&] (array<int, 4> i, array<int, 4> j) { if (i[2] != j[2]) return i[2] > j[2]; return i[3] > j[3]; }); sort(vals.begin(), vals.end()); vals.erase(unique(vals.begin(), vals.end()), vals.end()); map<int, int> hsh; for (int i = 0; i < vals.size(); i++) hsh[vals[i]] = i + 1; vector<int> ans(q); int o = 0; for (auto u : all) { if (u[3] == -1) { f1.Add(hsh[u[0]], 1); f2.Add(hsh[u[1]], 1); o += 1; } else { ans[u[3]] = o - f1.Get(hsh[u[0]]) - f2.Get(hsh[u[1]]); } } for (int i = 0; i < q; i++) cout << ans[i] << en; return 0; }

Compilation message (stderr)

examination.cpp: In function 'int main()':
examination.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for (int i = 0; i < vals.size(); i++) hsh[vals[i]] = i + 1;
      |                     ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...