# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
461223 |
2021-08-09T14:39:40 Z |
dxz05 |
Trading (IZhO13_trading) |
C++14 |
|
260 ms |
18624 KB |
#pragma GCC optimize("Ofast,O2,O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define revall(x) (x).rbegin(), (x).rend()
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
#define MP make_pair
typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 5e5 + 3e2;
const int M = 5522;
int n, m;
int t[N * 4];
void build(int v = 1, int tl = 1, int tr = n){
if (tl == tr){
t[v] = 1;
return;
}
int tm = (tl + tr) >> 1;
build(v + v, tl, tm);
build(v + v + 1, tm + 1, tr);
t[v] = t[v + v] + t[v + v + 1];
}
void update(int pos, int v = 1, int tl = 1, int tr = n){
if (tl == tr){
t[v] = 0;
return;
}
int tm = (tl + tr) >> 1;
if (pos <= tm) update(pos, v + v, tl, tm); else
update(pos, v + v + 1, tm + 1, tr);
t[v] = t[v + v] + t[v + v + 1];
}
int find(int k, int v = 1, int tl = 1, int tr = n){
if (k > t[v]) return n + 1;
if (tl == tr) return tl;
int tm = (tl + tr) >> 1;
if (t[v + v] >= k) return find(k, v + v, tl, tm); else
return find(k - t[v + v], v + v + 1, tm + 1, tr);
}
int f[N];
void add(int x, int y){
while (x < N){
f[x] += y;
x += (-x & x);
}
}
int get(int x){
int res = 0;
while (x > 0){
res += f[x];
x -= (-x & x);
}
return res;
}
int ans[N];
int lf[N], rg[N], val[N];
void solve(int TC) {
cin >> n >> m;
vector<int> perm(m);
for (int i = 1; i <= m; i++){
cin >> lf[i] >> rg[i] >> val[i];
perm[i - 1] = i;
}
for (int i = 1; i <= n; i++){
add(i, 1);
}
build();
sort(all(perm), [](int i, int j){
return val[i] - lf[i] > val[j] - lf[j];
});
for (int i : perm){
debug(i);
int cur = get(lf[i]);
if (get(lf[i]) - get(lf[i] - 1) == 0) cur++;
debug(cur);
int ind = find(cur);
while (ind <= rg[i]){
ans[ind] = val[i] + ind - lf[i];
update(ind);
add(ind, -1);
debug(cur, ind);
ind = find(cur);
}
}
for (int i = 1; i <= n; i++){
cout << ans[i] << ' ';
}
}
int main() {
startTime = clock();
cin.tie(nullptr);
cout.tie(nullptr);
ios_base::sync_with_stdio(false);
bool llololcal = false;
#ifdef dddxxz
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
llololcal = true;
#endif
int TC = 1;
//cin >> TC;
for (int test = 1; test <= TC; test++) {
debug(test);
//cout << "Case #" << test << ": ";
solve(test);
}
if (llololcal) cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
return 0;
}
Compilation message
trading.cpp: In function 'void solve(int)':
trading.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
trading.cpp:121:9: note: in expansion of macro 'debug'
121 | debug(i);
| ^~~~~
trading.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
trading.cpp:125:9: note: in expansion of macro 'debug'
125 | debug(cur);
| ^~~~~
trading.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
trading.cpp:133:13: note: in expansion of macro 'debug'
133 | debug(cur, ind);
| ^~~~~
trading.cpp: In function 'int main()':
trading.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
trading.cpp:162:9: note: in expansion of macro 'debug'
162 | debug(test);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
135 ms |
9456 KB |
Output is correct |
8 |
Correct |
148 ms |
10504 KB |
Output is correct |
9 |
Correct |
144 ms |
10548 KB |
Output is correct |
10 |
Correct |
153 ms |
10712 KB |
Output is correct |
11 |
Correct |
171 ms |
11948 KB |
Output is correct |
12 |
Correct |
180 ms |
12288 KB |
Output is correct |
13 |
Correct |
206 ms |
12776 KB |
Output is correct |
14 |
Correct |
192 ms |
12648 KB |
Output is correct |
15 |
Correct |
200 ms |
14028 KB |
Output is correct |
16 |
Correct |
216 ms |
14240 KB |
Output is correct |
17 |
Correct |
236 ms |
16212 KB |
Output is correct |
18 |
Correct |
223 ms |
17092 KB |
Output is correct |
19 |
Correct |
246 ms |
16648 KB |
Output is correct |
20 |
Correct |
260 ms |
18624 KB |
Output is correct |