# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1272455 | tminh | Matryoshka (JOI16_matryoshka) | C++20 | 1 ms | 576 KiB |
#include "bits/stdc++.h"
using namespace std;
#define task ""
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ep emplace_back
#define pb push_back
#define pf push_front
const ll mod = 1e9 + 7;
const int N = 1e6 + 5;
const int oo = 1e9;
bool START;
// so lan doc sol roi moi biet lam :
int n, q;
pii a[N];
set<pii> s;
vector<int> Q;
vector<pii> upd;
int id = 0;
void add() {
for (int val : Q) {
auto it = s.upper_bound(make_pair(val, oo));
if (it == s.end()) {
upd.pb(make_pair(val, id++));
} else {
int id_ = it->se;
s.erase(it);
upd.pb(make_pair(val, id_));
}
}
for (pii sad : upd) s.insert(sad);
Q.clear();
upd.clear();
}
inline void solve() {
while(q--) {
ll A, B; cin >> A >> B;
id = 0;
for (int i = 1; i <= n; ++i) {
if (a[i].fi >= A && a[i].se <= B) Q.pb(a[i].se);
if (i == n || a[i].fi != a[i + 1].fi) add();
}
cout << id << endl;
s.clear();
}
}
inline void input() {
cin >> n >> q;
for (int i = 1; i <= n; ++i) cin >> a[i].fi >> a[i].se;
return solve();
}
bool END;
int main() {
if(fopen(task ".inp", "r")) {
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
input();
cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl;
cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |