Submission #65670447
Source Code Expand
Copy
#include <bits/stdc++.h>using namespace std;using ll = long long;struct BIT {int n;vector<int> f;BIT(int _n): n(_n), f(n+1,0){}void update(int i,int v){ for(;i<=n;i+=i&-i) f[i]+=v; }int query(int i){ int s=0; for(;i>0;i-=i&-i) s+=f[i]; return s; }};int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int N,M;cin>>N>>M;int L=2*N;vector<pair<int,int>> chords(M);for(int i=0;i<M;i++){cin>>chords[i].first>>chords[i].second;
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct BIT {
int n;
vector<int> f;
BIT(int _n): n(_n), f(n+1,0){}
void update(int i,int v){ for(;i<=n;i+=i&-i) f[i]+=v; }
int query(int i){ int s=0; for(;i>0;i-=i&-i) s+=f[i]; return s; }
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
int L=2*N;
vector<pair<int,int>> chords(M);
for(int i=0;i<M;i++){
cin>>chords[i].first>>chords[i].second;
}
vector<int> even_pref(L+1,0), bi_pref(L+1,0);
for(auto &p:chords){
even_pref[p.first]++;
even_pref[p.second]++;
bi_pref[p.second]++;
}
for(int i=1;i<=L;i++){
even_pref[i]+=even_pref[i-1];
bi_pref[i]+=bi_pref[i-1];
}
sort(chords.begin(), chords.end(), [](auto &a, auto &b){
return a.first > b.first;
});
int Q;
cin>>Q;
struct Qry{int C,D,id; bool wrap;};
vector<Qry> qs(Q);
for(int i=0;i<Q;i++){
cin>>qs[i].C>>qs[i].D;
qs[i].id=i;
qs[i].wrap = qs[i].C > qs[i].D;
}
sort(qs.begin(), qs.end(), [](auto &a, auto &b){
return a.C > b.C;
});
BIT bit(L);
vector<ll> ans(Q);
int ptr=0, added=0;
for(auto &q:qs){
while(ptr<M && chords[ptr].first > q.C){
bit.update(chords[ptr].second,1);
ptr++;
added++;
}
ll E;
if(!q.wrap){
E = even_pref[q.D-1] - even_pref[q.C];
ll B = bit.query(q.D-1);
ans[q.id] = E - 2*B;
} else {
E = (even_pref[L] - even_pref[q.C]) + even_pref[q.D-1];
ll B_high = added;
ll B_low = bi_pref[q.D-1];
ll B = B_high + B_low;
ans[q.id] = E - 2*B;
}
}
for(int i=0;i<Q;i++){
cout << ans[i] << "\n";
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Chord Crossing |
| User | OYU__0YU |
| Language | C++ 20 (gcc 12.2) |
| Score | 525 |
| Code Size | 1973 Byte |
| Status | AC |
| Exec Time | 100 ms |
| Memory | 33064 KB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 525 / 525 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 01_small_09.txt, 02_large_00.txt, 02_large_01.txt, 02_large_02.txt, 02_large_03.txt, 02_large_04.txt, 02_large_05.txt, 02_large_06.txt, 02_large_07.txt, 02_large_08.txt, 02_large_09.txt, 02_large_10.txt, 02_large_11.txt, 02_large_12.txt, 02_large_13.txt, 02_large_14.txt, 02_large_15.txt, 02_large_16.txt, 02_large_17.txt, 02_large_18.txt, 02_large_19.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3480 KB |
| 00_sample_01.txt | AC | 1 ms | 3540 KB |
| 01_small_00.txt | AC | 35 ms | 7772 KB |
| 01_small_01.txt | AC | 35 ms | 7888 KB |
| 01_small_02.txt | AC | 35 ms | 7852 KB |
| 01_small_03.txt | AC | 35 ms | 7892 KB |
| 01_small_04.txt | AC | 34 ms | 7792 KB |
| 01_small_05.txt | AC | 35 ms | 7856 KB |
| 01_small_06.txt | AC | 35 ms | 7776 KB |
| 01_small_07.txt | AC | 35 ms | 7832 KB |
| 01_small_08.txt | AC | 36 ms | 7820 KB |
| 01_small_09.txt | AC | 35 ms | 7824 KB |
| 02_large_00.txt | AC | 73 ms | 30156 KB |
| 02_large_01.txt | AC | 84 ms | 31912 KB |
| 02_large_02.txt | AC | 75 ms | 31120 KB |
| 02_large_03.txt | AC | 86 ms | 30788 KB |
| 02_large_04.txt | AC | 86 ms | 32144 KB |
| 02_large_05.txt | AC | 77 ms | 31844 KB |
| 02_large_06.txt | AC | 68 ms | 31316 KB |
| 02_large_07.txt | AC | 88 ms | 30584 KB |
| 02_large_08.txt | AC | 66 ms | 29440 KB |
| 02_large_09.txt | AC | 94 ms | 32596 KB |
| 02_large_10.txt | AC | 99 ms | 32888 KB |
| 02_large_11.txt | AC | 100 ms | 32984 KB |
| 02_large_12.txt | AC | 100 ms | 32900 KB |
| 02_large_13.txt | AC | 99 ms | 32936 KB |
| 02_large_14.txt | AC | 99 ms | 32964 KB |
| 02_large_15.txt | AC | 99 ms | 32868 KB |
| 02_large_16.txt | AC | 100 ms | 32928 KB |
| 02_large_17.txt | AC | 99 ms | 32884 KB |
| 02_large_18.txt | AC | 99 ms | 32876 KB |
| 02_large_19.txt | AC | 98 ms | 32888 KB |
| 03_handmade_00.txt | AC | 1 ms | 3532 KB |
| 03_handmade_01.txt | AC | 92 ms | 32924 KB |
| 03_handmade_02.txt | AC | 86 ms | 32928 KB |
| 03_handmade_03.txt | AC | 91 ms | 32900 KB |
| 03_handmade_04.txt | AC | 89 ms | 32900 KB |
| 03_handmade_05.txt | AC | 92 ms | 32896 KB |
| 03_handmade_06.txt | AC | 86 ms | 32888 KB |
| 03_handmade_07.txt | AC | 91 ms | 33064 KB |