# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1092621 |
2024-09-24T15:11:50 Z |
ByeWorld |
RMQ (NOI17_rmq) |
C++14 |
|
1000 ms |
11264 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define int long long
#define ll long long
#define pb push_back
#define fi first
#define se second
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> ipii;
const int MAXN = 1e5+15;
const int INF = 1e18+10;
const int MOD = 998244353;
const int LOG = 32;
int n, m;
vector <ipii> vec;
vector <ipii> ran;
vector <int> add[MAXN];
vector <int> idx[MAXN];
bool tag[MAXN];
int ans[MAXN], ret[MAXN], mn[MAXN];
signed main(){
// ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i=1; i<=m; i++){
int l, r, mn; cin>>l>>r>>mn; l++; r++; mn++;
vec.pb({mn, {l, r}});
add[l].pb(mn); add[r+1].pb(-mn);
}
for(int i=1; i<=n; i++) ret[i] = n;
sort(vec.begin(), vec.end());
for(auto [val, ra] : vec){
int l = ra.fi, r = ra.se;
for(int i=l; i<=r; i++) ret[i] = val;
}
for(auto [val, ra] : vec){
int l = ra.fi, r = ra.se;
int mn = ret[l];
for(int i=l+1; i<=r; i++) mn = min(mn, ret[i]);
if(mn != val){
for(int i=1; i<=n; i++) cout << "-1 ";
cout << '\n';
exit(0);
}
}
for(int i=1; i<=n; i++) cout << ret[i]-1 << " \n"[i==n];
exit(0);
multiset <int> s;
for(int i=1; i<=n; i++){
for(auto in : add[i]){
if(in < 0) s.erase(s.find(-in));
else s.insert(in);
}
if(!s.empty()) mn[i] = *(s.begin());
}
sort(vec.begin(), vec.end());
for(int i=0; i<vec.size(); i++){
int id = i;
int mn = vec[i].se.se, mx = vec[i].se.fi;
while(i+1<vec.size() && vec[i+1].fi==vec[id].fi){
i++;
mn = min(mn, vec[i].se.se);
mx = max(mx, vec[i].se.fi);
}
if(mx <= mn) ran.pb({vec[id].fi, {mx, mn}});
else {
for(int j=1; j<=n; j++) cout << "-1 ";
cout << '\n';
exit(0);
}
}
// for(auto [val, in] : ran) cout << val << ' ' <<in.fi<<' '<<in.se << " in\n";
sort(ran.rbegin(), ran.rend());
for(auto [val, ra] : ran){
int l = ra.fi, r = ra.se;
for(int i=l; i<=r; i++){
if(ans[i] != 0) continue;
ans[i] = val;
}
tag[val] = 1;
}
// for(int i=1; i<=n; i++) cout << ans[i] << " \n"[i==n];
// for(int i=1; i<=n; i++) cout << mn[i] << " \n"[i==n];
// for(int i=1; i<=n; i++) cout << tag[i] << " \n"[i==n];
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(ret[j] != 0) continue;
if(tag[i] && ans[j] == i){
// cout << j << ' ' << i << " ji\n";
ret[j] = i; break;
} else if(!tag[i] && ans[j] <= i && mn[j] <= i){
// cout << j << ' ' << i << " jimn\n";
ret[j] = i; break;
}
}
}
bool done = 1;
for(int i=1; i<=n; i++)
if(ret[i] == 0) done = 0;
if(!done){
for(int i=1; i<=n; i++) cout << "-1 ";
cout << '\n';
} else {
for(int i=1; i<=n; i++) cout << ret[i]-1 << " \n"[i==n];
}
}
Compilation message
rmq.cpp: In function 'int main()':
rmq.cpp:37:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
37 | for(auto [val, ra] : vec){
| ^
rmq.cpp:41:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
41 | for(auto [val, ra] : vec){
| ^
rmq.cpp:64:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i=0; i<vec.size(); i++){
| ~^~~~~~~~~~~
rmq.cpp:67:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | while(i+1<vec.size() && vec[i+1].fi==vec[id].fi){
| ~~~^~~~~~~~~~~
rmq.cpp:81:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
81 | for(auto [val, ra] : ran){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
2 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
3 |
Partially correct |
2 ms |
4952 KB |
Output is partially correct |
4 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
5 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5052 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
2 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
3 |
Partially correct |
2 ms |
4952 KB |
Output is partially correct |
4 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
5 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5052 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
12 |
Partially correct |
3 ms |
5212 KB |
Output is partially correct |
13 |
Partially correct |
3 ms |
5212 KB |
Output is partially correct |
14 |
Partially correct |
3 ms |
4956 KB |
Output is partially correct |
15 |
Partially correct |
3 ms |
4956 KB |
Output is partially correct |
16 |
Partially correct |
3 ms |
5212 KB |
Output is partially correct |
17 |
Partially correct |
4 ms |
5212 KB |
Output is partially correct |
18 |
Partially correct |
3 ms |
4956 KB |
Output is partially correct |
19 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
20 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
21 |
Correct |
3 ms |
4956 KB |
Output is correct |
22 |
Correct |
3 ms |
4952 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
3 ms |
5212 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
2 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
3 |
Partially correct |
2 ms |
4952 KB |
Output is partially correct |
4 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
5 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5052 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
12 |
Partially correct |
3 ms |
5212 KB |
Output is partially correct |
13 |
Partially correct |
3 ms |
5212 KB |
Output is partially correct |
14 |
Partially correct |
3 ms |
4956 KB |
Output is partially correct |
15 |
Partially correct |
3 ms |
4956 KB |
Output is partially correct |
16 |
Partially correct |
3 ms |
5212 KB |
Output is partially correct |
17 |
Partially correct |
4 ms |
5212 KB |
Output is partially correct |
18 |
Partially correct |
3 ms |
4956 KB |
Output is partially correct |
19 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
20 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
21 |
Correct |
3 ms |
4956 KB |
Output is correct |
22 |
Correct |
3 ms |
4952 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
3 ms |
5212 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Partially correct |
2 ms |
4956 KB |
Output is partially correct |
27 |
Execution timed out |
1060 ms |
11264 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |