Submission #33315742
Source Code Expand
//thatsramen
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define ft first
#define sd second
#define pi pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(...) dbg_out(__VA_ARGS__)
using ll = long long;
using ld = long double;
using namespace std;
using namespace __gnu_pbds;
//Constants
const ll INF = 5 * 1e18;
const int IINF = 2 * 1e9;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ld PI = 3.14159265359;
//Templates
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '['; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << ']';}
void dbg_out() {cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); }
template<typename T> void mins(T& x, T y) {x = min(x, y);}
template<typename T> void maxs(T& x, T y) {x = max(x, y);}
template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
//order_of_key(k): number of elements strictly less than k
//find_by_order(k): k-th element in the set
void setPrec() {cout << fixed << setprecision(15);}
void unsyncIO() {cin.tie(0)->sync_with_stdio(0);}
void setIn(string s) {freopen(s.c_str(), "r", stdin);}
void setOut(string s) {freopen(s.c_str(), "w", stdout);}
void setIO(string s = "") {
unsyncIO(); setPrec();
if(s.size()) setIn(s + ".in"), setOut(s + ".out");
}
// #define TEST_CASES
void solve() {
int n, m;
cin >> n >> m;
vector<vector<int>> ps(m + 5);
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
ps[l].pb(i);
ps[r].pb(i);
}
vector<ll> ac(m + 5, 0);
vector<int> cnt(n, 0);
int on_c = 0;
for (int l = 1, r = 1; l <= m; l++) {
while (r <= m && on_c != n) {
for (int x : ps[r]) {
cnt[x]++;
if (cnt[x] == 1) on_c++;
}
r++;
}
if (on_c == n) {
int len = r - l;
ac[len]++;
if (len + m - r + 2 <= m)
ac[len + m - r + 2]--;
}
for (int x : ps[l]) {
if (cnt[x] == 1) on_c--;
cnt[x]--;
}
}
ll val = 0;
for (int i = 1; i <= m; i++) {
val += ac[i];
ac[i] = val;
}
for (int i = 1; i <= m; i++) {
cout << ac[i] << ' ';
}
}
int main() {
setIO();
int tt = 1;
#ifdef TEST_CASES
cin >> tt;
#endif
while (tt--)
solve();
return 0;
}
Submission Info
| Submission Time |
|
| Task |
E - At Least One |
| User |
thatsramen |
| Language |
C++ (GCC 9.2.1) |
| Score |
500 |
| Code Size |
3226 Byte |
| Status |
AC |
| Exec Time |
103 ms |
| Memory |
16340 KiB |
Compile Error
./Main.cpp: In function ‘void setIn(std::string)’:
./Main.cpp:44:30: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
44 | void setIn(string s) {freopen(s.c_str(), "r", stdin);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
./Main.cpp: In function ‘void setOut(std::string)’:
./Main.cpp:45:31: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
45 | void setOut(string s) {freopen(s.c_str(), "w", stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 02_max_00.txt, 03_min_00.txt, 04_corner_00.txt, 04_corner_01.txt, 04_corner_02.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
8 ms |
3500 KiB |
| 00_sample_01.txt |
AC |
2 ms |
3444 KiB |
| 00_sample_02.txt |
AC |
2 ms |
3640 KiB |
| 01_random_00.txt |
AC |
98 ms |
15732 KiB |
| 01_random_01.txt |
AC |
103 ms |
15732 KiB |
| 01_random_02.txt |
AC |
83 ms |
14680 KiB |
| 01_random_03.txt |
AC |
88 ms |
14732 KiB |
| 02_max_00.txt |
AC |
53 ms |
11740 KiB |
| 03_min_00.txt |
AC |
64 ms |
16340 KiB |
| 04_corner_00.txt |
AC |
28 ms |
9488 KiB |
| 04_corner_01.txt |
AC |
53 ms |
11760 KiB |
| 04_corner_02.txt |
AC |
54 ms |
12536 KiB |