結果
| 問題 | No.3085 Easy Problems |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-01-03 18:07:16 |
| 言語 | C++17(clang) (clang++ 21.1.8 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 709 ms / 2,000 ms |
| コード長 | 3,155 bytes |
| 記録 | |
| コンパイル時間 | 4,028 ms |
| コンパイル使用メモリ | 174,776 KB |
| 実行使用メモリ | 51,540 KB |
| 最終ジャッジ日時 | 2026-01-03 18:07:43 |
| 合計ジャッジ時間 | 26,406 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define forn(i, a, n) for (int i = a; i < n; i++)
#define fornr(i, a, n) for (int i = n - 1; i >= a; i--)
#define print(a) cout << a << "\n";
#define printarr(a) forn(i, 0, a.size()) cout << a[i] << " "; cout << endl;
#define file_read(filepath) freopen(filepath, "r", stdin);
#define file_write(filepath) freopen(filepath, "w", stdout);
#define f first
#define s second
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sorted(a) is_sorted(all(a))
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define vpii vector<pair<int,int>>
#define MOD1 1000000007
#define mii map<int,int>
#define sz(a) (int)a.size()
#define ld long double
template <class T> struct BIT {
int n;
vector<T> b, a;
BIT(int n) : n(n), b(n+1), a(n) {}
BIT(vector<T>& v) : BIT(v.size()) {
for (int i = 0; i < n; ++i) add(i, v[i]);
}
void add(int i, T v) {
a[i] += v;
for (++i; i <= n; i += i & -i) b[i] += v;
}
void set(int i, T v) { add(i, v - a[i]); }
T sum(int i) {
T r = 0;
for (++i; i; i -= i & -i) r += b[i];
return r;
}
T sum(int l, int r) { return sum(r) - (l ? sum(l - 1) : 0); }
int lower_bound(T x) {
int i = 0;
for (int k = 1 << __lg(n); k; k >>= 1)
if (i + k <= n && b[i + k] < x)
x -= b[i += k];
return i;
}
};
void solve(){
int n;
cin >> n;
vvi chal(100005);
vi compr;
forn(i,0,n){
int x, y;
cin >> x >> y;
chal[y].pb(x);
compr.pb(x);
}
int m;
cin >> m;
vector<array<int,3>> p(m);
vvi who(100005);
for(int i = 0; i < m; i++){
for(int j = 0; j < 2; j++){
cin >> p[i][j];
}
who[p[i][1]].pb(i);
p[i][2] = i;
compr.pb(p[i][0]);
}
sort(all(compr));
set<int> st(all(compr));
compr = vi();
compr.pb(0);
for(auto it : st){
compr.pb(it);
}
for(int i = 1; i <= 100000; i++){
for(int j = 0; j < sz(chal[i]); j++){
chal[i][j] = lower_bound(all(compr), chal[i][j]) - compr.begin();
}
}
//maintain fenwick.
BIT<int> fenw(500000);
for(int i = 1; i <= 100000; i++){
for(int j = 0; j < sz(chal[i]); j++){
fenw.add(chal[i][j], 1);
}
}
vi ans(m);
for(int i = 1; i <= 100000; i++){
//initially remove of this type from fenwick.
for(int j = 0; j < sz(chal[i]); j++){
fenw.add(chal[i][j], -1);
}
for(auto k : who[i]){
auto iska = lower_bound(all(compr), p[k][0]) - compr.begin();
int cur = fenw.sum(0, iska);
ans[k] = cur;
}
for(int j = 0; j < sz(chal[i]); j++){
fenw.add(chal[i][j], +1);
}
}
for(auto it : ans){
cout << it << endl;
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
vjudge1