Submission #1082802

#TimeUsernameProblemLanguageResultExecution timeMemory
1082802DeathIsAweExamination (JOI19_examination)C++17
20 / 100
225 ms22036 KiB
#include <bits/stdc++.h> using namespace std; int segmenta[262144], segmentb[262144]; unordered_map<int,int> compressa, compressb; void update(int x, int pos, int *segment) { pos += 131072; while (pos > 0) { segment[pos] += x; pos /= 2; } } int range(int a, int b, int *segment) { int val = 0; a += 131072; b += 131072; while (a <= b) { if (a%2 == 1) {val += segment[a++];} if (b%2 == 0) {val += segment[b--];} a/=2; b/=2; } return val; } void compress(vector<int> &arr, unordered_map<int,int> &compress) { sort(arr.begin(), arr.end()); int count = 0; compress[arr[0]] = 0; for (int i=1;i<arr.size();i++) { if (arr[i] > arr[i-1]) { count++; compress[arr[i]] = count; } } } void querycompress(vector<vector<int>> &q, vector<int> &arra, vector<int> &arrb) { int pos; for (int i=0;i<q.size();i++) { pos = lower_bound(arra.begin(), arra.end(), q[i][0]) - arra.begin(); if (pos == arra.size()) { q[i][0] = compressa[arra[pos-1]] + 1; } else { q[i][0] = compressa[arra[pos]]; } pos = lower_bound(arrb.begin(), arrb.end(), q[i][1]) - arrb.begin(); if (pos == arrb.size()) { q[i][1] = compressb[arrb[pos-1]] + 1; } else { q[i][1] = compressb[arrb[pos]]; } } } int main() { int n, q; cin >> n >> q; vector<vector<int>> ppl(n, vector<int>(3)); vector<int> arra(n), arrb(n), ansvec(q), query(4); vector<vector<int>> aq, bq; for (int i=0;i<n;i++) { cin >> ppl[i][0] >> ppl[i][1]; ppl[i][2] = ppl[i][0] + ppl[i][1]; arra[i] = ppl[i][0]; arrb[i] = ppl[i][1]; } for (int i=0;i<q;i++) { cin >> query[0] >> query[1] >> query[2]; query[3] = i; if (query[2] <= query[0] + query[1]) { aq.push_back(query); } else { bq.push_back(query); } } compress(arra, compressa); compress(arrb, compressb); for (int i=0;i<n;i++) { ppl[i][0] = compressa[ppl[i][0]]; ppl[i][1] = compressb[ppl[i][1]]; //cout << ppl[i][0] << ' ' << ppl[i][1] << '\n'; } querycompress(aq, arra, arrb); querycompress(bq, arra, arrb); for (int i=0;i<262144;i++) {segmentb[i] = 0;} sort(ppl.begin(), ppl.end(), greater<vector<int>>()); sort(aq.begin(), aq.end(), greater<vector<int>>()); //for (int i=0;i<aq.size();i++) { // cout << aq[i][0] << ' ' << aq[i][1] << ' ' << aq[i][2] << ' ' << aq[i][3] << '\n'; //} int tracker = 0; for (int i=0;i<aq.size();i++) { while (tracker < n && ppl[tracker][0] >= aq[i][0]) { update(1, ppl[tracker][1], segmentb); tracker++; } ansvec[aq[i][3]] = range(aq[i][1], 131071, segmentb); } for (int i: ansvec) { cout << i << '\n'; } }

Compilation message (stderr)

examination.cpp: In function 'void compress(std::vector<int>&, std::unordered_map<int, int>&)':
examination.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int i=1;i<arr.size();i++) {
      |                  ~^~~~~~~~~~~
examination.cpp: In function 'void querycompress(std::vector<std::vector<int> >&, std::vector<int>&, std::vector<int>&)':
examination.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i=0;i<q.size();i++) {
      |                  ~^~~~~~~~~
examination.cpp:43:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         if (pos == arra.size()) {
      |             ~~~~^~~~~~~~~~~~~~
examination.cpp:49:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         if (pos == arrb.size()) {
      |             ~~~~^~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:94:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for (int i=0;i<aq.size();i++) {
      |                  ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...