Submission #998054

# Submission time Handle Problem Language Result Execution time Memory
998054 2024-06-13T08:54:32 Z vjudge1 Examination (JOI19_examination) C++14
100 / 100
320 ms 41532 KB
#include <bits/stdc++.h>
using namespace std; 

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

#define fi first
#define se second
#define all(a) (a).begin(), (a).end()

const ll N = 2e5 + 5;
const ll blocksz = 505;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll n, q;
ll cnt[N], ans[N];
map<ll, ll> mp;

struct Info{
     ll x, y, z, id;
} a[N];

struct BIT{
     ll b[N];
     void upd(ll i, ll x){
          for (; i <= n + q; i += i & (-i)) b[i] += x;
     }
     ll get(ll i){
          ll ans = 0;
          for (; i; i -= i & (-i)) ans += b[i];
          return ans;
     }
} ft;

vector<ll> record;
vector<Info> tmp;

void CDQ(ll l, ll r){
     if (l == r) return;
     ll m = l + r >> 1;
     CDQ(l, m); CDQ(m + 1, r);

     ll i = l, j = m + 1, sum = 0;
     while (i <= m && j <= r){
          if (a[i].y > a[j].y){
               if (a[i].id <= n){
                    ++sum; ft.upd(a[i].z, 1); record.push_back(a[i].z);
               }
               tmp.push_back(a[i++]);
          }else{
               ans[a[j].id] += sum - ft.get(a[j].z); tmp.push_back(a[j++]);
          }    
     }

     while (i <= m) tmp.push_back(a[i++]);
     while (j <= r) ans[a[j].id] += sum - ft.get(a[j].z), tmp.push_back(a[j++]);

     for (int i = l; i <= r; ++i) a[i] = tmp[i - l];
     for (int i : record) ft.upd(i, -1);
     
     vector<ll> ().swap(record);
     vector<Info> ().swap(tmp);
}

void solve(){
     cin >> n >> q;
     vector<ll> v;
     for (int i = 1; i <= n; ++i){
          cin >> a[i].x >> a[i].y; a[i].z = a[i].x + a[i].y; a[i].id = i;
          v.push_back(a[i].z);
     }
     for (int i = n + 1; i <= n + q; ++i){
          cin >> a[i].x >> a[i].y >> a[i].z; a[i].id = i;
          --a[i].x; --a[i].y; --a[i].z;
          v.push_back(a[i].z); 
     }

     sort(all(v));
     v.erase(unique(all(v)), v.end());
     for (int i = 0; i < v.size(); ++i) mp[v[i]] = i + 1;
     for (int i = 1; i <= n + q; ++i) a[i].z = mp[a[i].z];

     sort(a + 1, a + n + q + 1, [&](Info A, Info B){
          return (A.x == B.x ? (A.y == B.y ? A.z < B.z : A.y < B.y) : A.x > B.x);
     });

     CDQ(1, n + q);
     for (int i = n + 1; i <= n + q; ++i) cout << ans[i] << "\n";
}    

signed main(){
     ios_base::sync_with_stdio(0); 
     cin.tie(0); cout.tie(0);
     ll run_case = 1; // cin >> run_case;
     while (run_case--){
          solve();
     }
}

Compilation message

examination.cpp: In function 'void CDQ(ll, ll)':
examination.cpp:42:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |      ll m = l + r >> 1;
      |             ~~^~~
examination.cpp: In function 'void solve()':
examination.cpp:82:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |      for (int i = 0; i < v.size(); ++i) mp[v[i]] = i + 1;
      |                      ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 6 ms 5276 KB Output is correct
8 Correct 6 ms 5320 KB Output is correct
9 Correct 7 ms 5276 KB Output is correct
10 Correct 6 ms 5344 KB Output is correct
11 Correct 5 ms 5276 KB Output is correct
12 Correct 3 ms 5048 KB Output is correct
13 Correct 5 ms 5180 KB Output is correct
14 Correct 7 ms 5276 KB Output is correct
15 Correct 5 ms 5172 KB Output is correct
16 Correct 4 ms 5176 KB Output is correct
17 Correct 5 ms 5340 KB Output is correct
18 Correct 3 ms 5048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 227 ms 33080 KB Output is correct
2 Correct 224 ms 31344 KB Output is correct
3 Correct 217 ms 32452 KB Output is correct
4 Correct 197 ms 31508 KB Output is correct
5 Correct 175 ms 32236 KB Output is correct
6 Correct 117 ms 27968 KB Output is correct
7 Correct 238 ms 31752 KB Output is correct
8 Correct 215 ms 31752 KB Output is correct
9 Correct 201 ms 32240 KB Output is correct
10 Correct 153 ms 31208 KB Output is correct
11 Correct 189 ms 31344 KB Output is correct
12 Correct 95 ms 27128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 227 ms 33080 KB Output is correct
2 Correct 224 ms 31344 KB Output is correct
3 Correct 217 ms 32452 KB Output is correct
4 Correct 197 ms 31508 KB Output is correct
5 Correct 175 ms 32236 KB Output is correct
6 Correct 117 ms 27968 KB Output is correct
7 Correct 238 ms 31752 KB Output is correct
8 Correct 215 ms 31752 KB Output is correct
9 Correct 201 ms 32240 KB Output is correct
10 Correct 153 ms 31208 KB Output is correct
11 Correct 189 ms 31344 KB Output is correct
12 Correct 95 ms 27128 KB Output is correct
13 Correct 268 ms 35052 KB Output is correct
14 Correct 272 ms 34784 KB Output is correct
15 Correct 221 ms 32280 KB Output is correct
16 Correct 251 ms 33924 KB Output is correct
17 Correct 209 ms 33504 KB Output is correct
18 Correct 119 ms 27616 KB Output is correct
19 Correct 278 ms 34980 KB Output is correct
20 Correct 269 ms 35520 KB Output is correct
21 Correct 284 ms 34600 KB Output is correct
22 Correct 143 ms 32528 KB Output is correct
23 Correct 182 ms 30960 KB Output is correct
24 Correct 94 ms 28664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 6 ms 5276 KB Output is correct
8 Correct 6 ms 5320 KB Output is correct
9 Correct 7 ms 5276 KB Output is correct
10 Correct 6 ms 5344 KB Output is correct
11 Correct 5 ms 5276 KB Output is correct
12 Correct 3 ms 5048 KB Output is correct
13 Correct 5 ms 5180 KB Output is correct
14 Correct 7 ms 5276 KB Output is correct
15 Correct 5 ms 5172 KB Output is correct
16 Correct 4 ms 5176 KB Output is correct
17 Correct 5 ms 5340 KB Output is correct
18 Correct 3 ms 5048 KB Output is correct
19 Correct 227 ms 33080 KB Output is correct
20 Correct 224 ms 31344 KB Output is correct
21 Correct 217 ms 32452 KB Output is correct
22 Correct 197 ms 31508 KB Output is correct
23 Correct 175 ms 32236 KB Output is correct
24 Correct 117 ms 27968 KB Output is correct
25 Correct 238 ms 31752 KB Output is correct
26 Correct 215 ms 31752 KB Output is correct
27 Correct 201 ms 32240 KB Output is correct
28 Correct 153 ms 31208 KB Output is correct
29 Correct 189 ms 31344 KB Output is correct
30 Correct 95 ms 27128 KB Output is correct
31 Correct 268 ms 35052 KB Output is correct
32 Correct 272 ms 34784 KB Output is correct
33 Correct 221 ms 32280 KB Output is correct
34 Correct 251 ms 33924 KB Output is correct
35 Correct 209 ms 33504 KB Output is correct
36 Correct 119 ms 27616 KB Output is correct
37 Correct 278 ms 34980 KB Output is correct
38 Correct 269 ms 35520 KB Output is correct
39 Correct 284 ms 34600 KB Output is correct
40 Correct 143 ms 32528 KB Output is correct
41 Correct 182 ms 30960 KB Output is correct
42 Correct 94 ms 28664 KB Output is correct
43 Correct 310 ms 39980 KB Output is correct
44 Correct 316 ms 40968 KB Output is correct
45 Correct 296 ms 41532 KB Output is correct
46 Correct 295 ms 40352 KB Output is correct
47 Correct 262 ms 40036 KB Output is correct
48 Correct 125 ms 27604 KB Output is correct
49 Correct 293 ms 40228 KB Output is correct
50 Correct 303 ms 39508 KB Output is correct
51 Correct 320 ms 39384 KB Output is correct
52 Correct 242 ms 39736 KB Output is correct
53 Correct 196 ms 34992 KB Output is correct