# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1107494 | 2024-11-01T09:55:13 Z | InvMOD | Examination (JOI19_examination) | C++14 | 343 ms | 20448 KB |
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define gcd __gcd #define sz(v) (int) v.size() #define pb push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define compact(v) (v).erase(unique(all(v)), (v).end()) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define dbg(x) "[" #x " = " << (x) << "]" ///#define int long long using ll = long long; using ld = long double; using ull = unsigned long long; template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;} template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;} const int N = 1e5+5; const ll MOD = 1e9+7; const ll INF = 1e18; struct Query{ /* -1: Update, +1: Query */ int x, y, z, op; Query(int x = 0, int y = 0 ,int z = 0, int op = 0): x(x), y(y), z(z), op(op) {} bool operator < (const Query& q) const{ if(z != q.z) return z > q.z; else{ return op < q.op; } } }; int n, q, bit[6*N], answer[N]; Query Q[N<<1]; vector<int> compress; void update(int p, int val){ for(; p <= sz(compress); p += p&-p) bit[p] += val; return; } int get(int p){ int res = 0; for(; p; p -= p&-p) res += bit[p]; return res; } int get_range(int l, int r){return get(r) - get(l-1);} void Dnc(int l, int r){ if(l == r){ return; } else{ int m = l+r>>1; vector<Query> Upd, Que; for(int i = l; i <= m; i++) if(Q[i].op < 0) Upd.pb(Q[i]); for(int i = m+1; i <= r; i++) if(Q[i].op > 0) Que.pb(Q[i]); sort(all(Upd), [&](Query x, Query y){return x.x > y.x;}); sort(all(Que), [&](Query x, Query y){return x.x > y.x;}); stack<int> save_Upd; int pointer = 0; for(Query &cur_q : Que){ while(pointer < sz(Upd) && Upd[pointer].x >= cur_q.x){ update(Upd[pointer].y, 1); save_Upd.push(Upd[pointer++].y); } answer[cur_q.op] += get_range(cur_q.y, sz(compress)); } while(sz(save_Upd)){ update(save_Upd.top(), -1); save_Upd.pop(); } Dnc(l, m), Dnc(m+1, r); } return; } void solve() { cin >> n >> q; for(int i = 1; i <= n; i++){ int x,y; cin >> x >> y; Q[i] = Query(x, y, x+y, -1); compress.pb(x), compress.pb(y), compress.pb(x+y); } for(int i = n+1; i <= n+q; i++){ int x,y,z; cin >> x >> y >> z; Q[i] = Query(x, y, z, i-n); compress.pb(x), compress.pb(y), compress.pb(z); } sort(all(compress)), compact(compress); for(int i = 1; i <= n+q; i++){ Q[i].x = lower_bound(all(compress), Q[i].x) - compress.begin()+1; Q[i].y = lower_bound(all(compress), Q[i].y) - compress.begin()+1; Q[i].z = lower_bound(all(compress), Q[i].z) - compress.begin()+1; } sort(Q+1, Q+1+n+q); Dnc(1, n+q); for(int i = 1; i <= q; i++){ cout << answer[i] <<"\n"; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP","r",stdin); freopen(name".OUT","w",stdout); } int t = 1; //cin >> t; while(t--) solve(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4688 KB | Output is correct |
2 | Correct | 1 ms | 4688 KB | Output is correct |
3 | Correct | 1 ms | 4688 KB | Output is correct |
4 | Correct | 2 ms | 4856 KB | Output is correct |
5 | Correct | 1 ms | 4688 KB | Output is correct |
6 | Correct | 2 ms | 4688 KB | Output is correct |
7 | Correct | 8 ms | 4944 KB | Output is correct |
8 | Correct | 8 ms | 4944 KB | Output is correct |
9 | Correct | 8 ms | 5096 KB | Output is correct |
10 | Correct | 7 ms | 4944 KB | Output is correct |
11 | Correct | 7 ms | 4956 KB | Output is correct |
12 | Correct | 6 ms | 4944 KB | Output is correct |
13 | Correct | 6 ms | 4992 KB | Output is correct |
14 | Correct | 7 ms | 5136 KB | Output is correct |
15 | Correct | 7 ms | 4944 KB | Output is correct |
16 | Correct | 5 ms | 5008 KB | Output is correct |
17 | Correct | 6 ms | 4944 KB | Output is correct |
18 | Correct | 4 ms | 4888 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 225 ms | 17252 KB | Output is correct |
2 | Correct | 233 ms | 17104 KB | Output is correct |
3 | Correct | 238 ms | 18120 KB | Output is correct |
4 | Correct | 181 ms | 16356 KB | Output is correct |
5 | Correct | 174 ms | 16568 KB | Output is correct |
6 | Correct | 129 ms | 15600 KB | Output is correct |
7 | Correct | 222 ms | 18168 KB | Output is correct |
8 | Correct | 228 ms | 17084 KB | Output is correct |
9 | Correct | 242 ms | 17080 KB | Output is correct |
10 | Correct | 169 ms | 16568 KB | Output is correct |
11 | Correct | 163 ms | 16340 KB | Output is correct |
12 | Correct | 88 ms | 15728 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 225 ms | 17252 KB | Output is correct |
2 | Correct | 233 ms | 17104 KB | Output is correct |
3 | Correct | 238 ms | 18120 KB | Output is correct |
4 | Correct | 181 ms | 16356 KB | Output is correct |
5 | Correct | 174 ms | 16568 KB | Output is correct |
6 | Correct | 129 ms | 15600 KB | Output is correct |
7 | Correct | 222 ms | 18168 KB | Output is correct |
8 | Correct | 228 ms | 17084 KB | Output is correct |
9 | Correct | 242 ms | 17080 KB | Output is correct |
10 | Correct | 169 ms | 16568 KB | Output is correct |
11 | Correct | 163 ms | 16340 KB | Output is correct |
12 | Correct | 88 ms | 15728 KB | Output is correct |
13 | Correct | 288 ms | 16364 KB | Output is correct |
14 | Correct | 273 ms | 17008 KB | Output is correct |
15 | Correct | 233 ms | 17100 KB | Output is correct |
16 | Correct | 252 ms | 14776 KB | Output is correct |
17 | Correct | 245 ms | 14780 KB | Output is correct |
18 | Correct | 126 ms | 14780 KB | Output is correct |
19 | Correct | 305 ms | 15736 KB | Output is correct |
20 | Correct | 285 ms | 16056 KB | Output is correct |
21 | Correct | 289 ms | 15544 KB | Output is correct |
22 | Correct | 144 ms | 17368 KB | Output is correct |
23 | Correct | 168 ms | 16320 KB | Output is correct |
24 | Correct | 91 ms | 15548 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4688 KB | Output is correct |
2 | Correct | 1 ms | 4688 KB | Output is correct |
3 | Correct | 1 ms | 4688 KB | Output is correct |
4 | Correct | 2 ms | 4856 KB | Output is correct |
5 | Correct | 1 ms | 4688 KB | Output is correct |
6 | Correct | 2 ms | 4688 KB | Output is correct |
7 | Correct | 8 ms | 4944 KB | Output is correct |
8 | Correct | 8 ms | 4944 KB | Output is correct |
9 | Correct | 8 ms | 5096 KB | Output is correct |
10 | Correct | 7 ms | 4944 KB | Output is correct |
11 | Correct | 7 ms | 4956 KB | Output is correct |
12 | Correct | 6 ms | 4944 KB | Output is correct |
13 | Correct | 6 ms | 4992 KB | Output is correct |
14 | Correct | 7 ms | 5136 KB | Output is correct |
15 | Correct | 7 ms | 4944 KB | Output is correct |
16 | Correct | 5 ms | 5008 KB | Output is correct |
17 | Correct | 6 ms | 4944 KB | Output is correct |
18 | Correct | 4 ms | 4888 KB | Output is correct |
19 | Correct | 225 ms | 17252 KB | Output is correct |
20 | Correct | 233 ms | 17104 KB | Output is correct |
21 | Correct | 238 ms | 18120 KB | Output is correct |
22 | Correct | 181 ms | 16356 KB | Output is correct |
23 | Correct | 174 ms | 16568 KB | Output is correct |
24 | Correct | 129 ms | 15600 KB | Output is correct |
25 | Correct | 222 ms | 18168 KB | Output is correct |
26 | Correct | 228 ms | 17084 KB | Output is correct |
27 | Correct | 242 ms | 17080 KB | Output is correct |
28 | Correct | 169 ms | 16568 KB | Output is correct |
29 | Correct | 163 ms | 16340 KB | Output is correct |
30 | Correct | 88 ms | 15728 KB | Output is correct |
31 | Correct | 288 ms | 16364 KB | Output is correct |
32 | Correct | 273 ms | 17008 KB | Output is correct |
33 | Correct | 233 ms | 17100 KB | Output is correct |
34 | Correct | 252 ms | 14776 KB | Output is correct |
35 | Correct | 245 ms | 14780 KB | Output is correct |
36 | Correct | 126 ms | 14780 KB | Output is correct |
37 | Correct | 305 ms | 15736 KB | Output is correct |
38 | Correct | 285 ms | 16056 KB | Output is correct |
39 | Correct | 289 ms | 15544 KB | Output is correct |
40 | Correct | 144 ms | 17368 KB | Output is correct |
41 | Correct | 168 ms | 16320 KB | Output is correct |
42 | Correct | 91 ms | 15548 KB | Output is correct |
43 | Correct | 326 ms | 19384 KB | Output is correct |
44 | Correct | 343 ms | 18876 KB | Output is correct |
45 | Correct | 313 ms | 20448 KB | Output is correct |
46 | Correct | 269 ms | 16056 KB | Output is correct |
47 | Correct | 251 ms | 16832 KB | Output is correct |
48 | Correct | 128 ms | 13496 KB | Output is correct |
49 | Correct | 305 ms | 20300 KB | Output is correct |
50 | Correct | 321 ms | 19308 KB | Output is correct |
51 | Correct | 320 ms | 20152 KB | Output is correct |
52 | Correct | 228 ms | 16312 KB | Output is correct |
53 | Correct | 172 ms | 17168 KB | Output is correct |