Submission #71492793
Source Code Expand
/*
JAI JAGANNATH!
*/
//@Author : zanj0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
// #define LOCAL // ← enable locally via -DLOCAL; keep commented for OJ
#define ff first
#define ss second
#define pb push_back
#define MOD 1000000007
#define inf 1000000000000000000LL
#define ps(x, y) fixed << setprecision(y) << x
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define endl "\n"
#define timetaken cerr << "Time : " << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC << "ms\n"
typedef long long int lli;
#ifdef LOCAL
#define dbg(x) cerr << "[DBG] " << #x << " = " << (x) << '\n'
template <class A, class B>
ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ',' << p.second << ')'; }
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
os << '[';
for (size_t i = 0; i < v.size(); ++i)
{
if (i)
os << ',';
os << v[i];
}
return os << ']';
}
template <class K, class V>
ostream &operator<<(ostream &os, const map<K, V> &mp)
{
os << '{';
bool first = true;
for (const auto &kv : mp)
{
if (!first)
os << ',';
first = false;
os << kv.first << ':' << kv.second;
}
return os << '}';
}
template <class K, class V>
ostream &operator<<(ostream &os, const unordered_map<K, V> &mp)
{
os << '{';
bool first = true;
for (const auto &kv : mp)
{
if (!first)
os << ',';
first = false;
os << kv.first << ':' << kv.second;
}
return os << '}';
}
#else
#define dbg(x) ((void)0)
#endif
void zanj0()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
}
/*
────────────────────────────────────────────────────────────────────────
Problem Statement:
Observations:
Claims:
────────────────────────────────────────────────────────────────────────
*/
set<pair<lli, lli>> has;
lli ret;
void Remove(pair<lli, lli> v){
if(!has.count(v)) return ;
has.erase(v);
ret += (v.ss - v.ff + 1);
}
void Insert(pair<lli, lli> v)
{
auto it = has.lower_bound({v.ff, -1});
dbg(v);
if (it != has.begin())
{
auto it2 = prev(it);
if (it2->ss >= v.ff){
dbg(*it2);
pair<lli, lli> last = *it2;
it = it2;
it++;
Remove(last);
v.ff = min(v.ff, last.ff);
v.ss = max(v.ss, last.ss);
}
}
dbg("-- ");
dbg(v);
vector<pair<lli, lli>> to_remove;
while(it != has.end()){
if(v.ss >= it->ff){
// Overlap
to_remove.pb(*it);
v.ff = min(v.ff, it->ff);
v.ss = max(v.ss, it->ss);
}else break;
it++;
}
for(auto& it : to_remove){
Remove(it);
}
ret -= (v.ss - v.ff + 1);
has.insert(v);
}
void Solve()
{
lli n;
cin >> n;
lli q;
cin >> q;
ret = n;
while (q--)
{
lli l, r;
cin >> l >> r;
dbg(l);
dbg(r);
Insert({l, r});
// for(auto& it : has){
// cout << it.ff << " -- " << it.ss << endl;
// }
cout << ret << endl;
}
}
int32_t main()
{
zanj0();
Solve();
timetaken;
return 0;
}
/*
GOLDEN RULES
• Solutions are simple.
• Proofs are simple.
• Implementations are simple.
*/
Submission Info
| Submission Time | |
|---|---|
| Task | E - Cover query |
| User | zanj0 |
| Language | C++23 (GCC 15.2.0) |
| Score | 450 |
| Code Size | 4248 Byte |
| Status | AC |
| Exec Time | 144 ms |
| Memory | 20248 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 450 / 450 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00.txt, example_01.txt |
| All | example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00.txt | AC | 1 ms | 3876 KiB |
| example_01.txt | AC | 1 ms | 3840 KiB |
| hand_00.txt | AC | 80 ms | 16392 KiB |
| hand_01.txt | AC | 79 ms | 16304 KiB |
| hand_02.txt | AC | 34 ms | 3848 KiB |
| hand_03.txt | AC | 34 ms | 3908 KiB |
| hand_04.txt | AC | 91 ms | 20124 KiB |
| hand_05.txt | AC | 81 ms | 20248 KiB |
| hand_06.txt | AC | 67 ms | 10176 KiB |
| hand_07.txt | AC | 30 ms | 3904 KiB |
| hand_08.txt | AC | 29 ms | 3908 KiB |
| hand_09.txt | AC | 37 ms | 3760 KiB |
| hand_10.txt | AC | 27 ms | 3792 KiB |
| hand_11.txt | AC | 28 ms | 3908 KiB |
| random_00.txt | AC | 33 ms | 3788 KiB |
| random_01.txt | AC | 33 ms | 3760 KiB |
| random_02.txt | AC | 33 ms | 3908 KiB |
| random_03.txt | AC | 34 ms | 3760 KiB |
| random_04.txt | AC | 33 ms | 3908 KiB |
| random_05.txt | AC | 141 ms | 8484 KiB |
| random_06.txt | AC | 141 ms | 8544 KiB |
| random_07.txt | AC | 141 ms | 8340 KiB |
| random_08.txt | AC | 142 ms | 8548 KiB |
| random_09.txt | AC | 144 ms | 8508 KiB |
| random_10.txt | AC | 34 ms | 3828 KiB |
| random_11.txt | AC | 33 ms | 3908 KiB |
| random_12.txt | AC | 33 ms | 3908 KiB |
| random_13.txt | AC | 33 ms | 3848 KiB |
| random_14.txt | AC | 33 ms | 3760 KiB |
| random_15.txt | AC | 36 ms | 4036 KiB |
| random_16.txt | AC | 35 ms | 3972 KiB |
| random_17.txt | AC | 35 ms | 3920 KiB |
| random_18.txt | AC | 35 ms | 3968 KiB |
| random_19.txt | AC | 36 ms | 4016 KiB |
| random_20.txt | AC | 120 ms | 5604 KiB |
| random_21.txt | AC | 120 ms | 5424 KiB |
| random_22.txt | AC | 120 ms | 5504 KiB |
| random_23.txt | AC | 120 ms | 5728 KiB |
| random_24.txt | AC | 120 ms | 5604 KiB |
| random_25.txt | AC | 36 ms | 3900 KiB |
| random_26.txt | AC | 36 ms | 3760 KiB |
| random_27.txt | AC | 38 ms | 3840 KiB |