답안 #998051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998051 2024-06-13T08:53:56 Z fimh Examination (JOI19_examination) C++14
100 / 100
361 ms 41120 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;
      |                      ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 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 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 6 ms 5276 KB Output is correct
8 Correct 7 ms 5276 KB Output is correct
9 Correct 6 ms 5276 KB Output is correct
10 Correct 6 ms 5276 KB Output is correct
11 Correct 5 ms 5276 KB Output is correct
12 Correct 4 ms 5048 KB Output is correct
13 Correct 5 ms 5432 KB Output is correct
14 Correct 6 ms 5160 KB Output is correct
15 Correct 5 ms 5164 KB Output is correct
16 Correct 4 ms 5180 KB Output is correct
17 Correct 5 ms 5288 KB Output is correct
18 Correct 3 ms 5048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 222 ms 32228 KB Output is correct
2 Correct 235 ms 32912 KB Output is correct
3 Correct 227 ms 32864 KB Output is correct
4 Correct 219 ms 31004 KB Output is correct
5 Correct 172 ms 31672 KB Output is correct
6 Correct 157 ms 28148 KB Output is correct
7 Correct 250 ms 31492 KB Output is correct
8 Correct 233 ms 32484 KB Output is correct
9 Correct 235 ms 32100 KB Output is correct
10 Correct 170 ms 32280 KB Output is correct
11 Correct 202 ms 31960 KB Output is correct
12 Correct 110 ms 27320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 222 ms 32228 KB Output is correct
2 Correct 235 ms 32912 KB Output is correct
3 Correct 227 ms 32864 KB Output is correct
4 Correct 219 ms 31004 KB Output is correct
5 Correct 172 ms 31672 KB Output is correct
6 Correct 157 ms 28148 KB Output is correct
7 Correct 250 ms 31492 KB Output is correct
8 Correct 233 ms 32484 KB Output is correct
9 Correct 235 ms 32100 KB Output is correct
10 Correct 170 ms 32280 KB Output is correct
11 Correct 202 ms 31960 KB Output is correct
12 Correct 110 ms 27320 KB Output is correct
13 Correct 325 ms 36348 KB Output is correct
14 Correct 302 ms 35776 KB Output is correct
15 Correct 278 ms 32820 KB Output is correct
16 Correct 282 ms 32920 KB Output is correct
17 Correct 228 ms 34100 KB Output is correct
18 Correct 129 ms 26956 KB Output is correct
19 Correct 278 ms 35964 KB Output is correct
20 Correct 268 ms 34984 KB Output is correct
21 Correct 290 ms 35832 KB Output is correct
22 Correct 182 ms 32672 KB Output is correct
23 Correct 195 ms 31088 KB Output is correct
24 Correct 113 ms 28256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 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 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 6 ms 5276 KB Output is correct
8 Correct 7 ms 5276 KB Output is correct
9 Correct 6 ms 5276 KB Output is correct
10 Correct 6 ms 5276 KB Output is correct
11 Correct 5 ms 5276 KB Output is correct
12 Correct 4 ms 5048 KB Output is correct
13 Correct 5 ms 5432 KB Output is correct
14 Correct 6 ms 5160 KB Output is correct
15 Correct 5 ms 5164 KB Output is correct
16 Correct 4 ms 5180 KB Output is correct
17 Correct 5 ms 5288 KB Output is correct
18 Correct 3 ms 5048 KB Output is correct
19 Correct 222 ms 32228 KB Output is correct
20 Correct 235 ms 32912 KB Output is correct
21 Correct 227 ms 32864 KB Output is correct
22 Correct 219 ms 31004 KB Output is correct
23 Correct 172 ms 31672 KB Output is correct
24 Correct 157 ms 28148 KB Output is correct
25 Correct 250 ms 31492 KB Output is correct
26 Correct 233 ms 32484 KB Output is correct
27 Correct 235 ms 32100 KB Output is correct
28 Correct 170 ms 32280 KB Output is correct
29 Correct 202 ms 31960 KB Output is correct
30 Correct 110 ms 27320 KB Output is correct
31 Correct 325 ms 36348 KB Output is correct
32 Correct 302 ms 35776 KB Output is correct
33 Correct 278 ms 32820 KB Output is correct
34 Correct 282 ms 32920 KB Output is correct
35 Correct 228 ms 34100 KB Output is correct
36 Correct 129 ms 26956 KB Output is correct
37 Correct 278 ms 35964 KB Output is correct
38 Correct 268 ms 34984 KB Output is correct
39 Correct 290 ms 35832 KB Output is correct
40 Correct 182 ms 32672 KB Output is correct
41 Correct 195 ms 31088 KB Output is correct
42 Correct 113 ms 28256 KB Output is correct
43 Correct 341 ms 40436 KB Output is correct
44 Correct 361 ms 39476 KB Output is correct
45 Correct 320 ms 39748 KB Output is correct
46 Correct 315 ms 41120 KB Output is correct
47 Correct 283 ms 40844 KB Output is correct
48 Correct 128 ms 27612 KB Output is correct
49 Correct 318 ms 40304 KB Output is correct
50 Correct 333 ms 40864 KB Output is correct
51 Correct 325 ms 39444 KB Output is correct
52 Correct 277 ms 39216 KB Output is correct
53 Correct 204 ms 34700 KB Output is correct