# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
243606 |
2020-07-01T11:58:21 Z |
SamAnd |
RMQ (NOI17_rmq) |
C++17 |
|
109 ms |
10936 KB |
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 100005;
int n, q;
pair<int, int> u[N];
int t[N * 4];
void ubd(int tl, int tr, int l, int r, int y, int pos)
{
if (l > r)
return;
if (tl == l && tr == r)
{
t[pos] = max(t[pos], y);
return;
}
int m = (tl + tr) / 2;
ubd(tl, m, l, min(m, r), y, pos * 2);
ubd(m + 1, tr, max(m + 1, l), r, y, pos * 2 + 1);
}
int qry(int tl, int tr, int x, int pos)
{
if (tl == tr)
return t[pos];
int m = (tl + tr) / 2;
if (x <= m)
return max(qry(tl, m, x, pos * 2), t[pos]);
return max(qry(m + 1, tr, x, pos * 2 + 1), t[pos]);
}
pair<int, int> hat(const pair<int, int>& a, const pair<int, int>& b)
{
return m_p(max(a.fi, b.fi), min(a.se, b.se));
}
vector<int> v[N];
int ans[N];
void solv()
{
scanf("%d%d", &n, &q);
for (int i = 0; i < n; ++i)
u[i] = m_p(0, n - 1);
for (int i = 0; i < q; ++i)
{
int l, r, y;
scanf("%d%d%d", &l, &r, &y);
ubd(0, n - 1, l, r, y, 1);
u[y] = hat(u[y], m_p(l, r));
}
for (int i = 0; i < n; ++i)
{
if (u[i].fi > u[i].se)
{
for (int i = 0; i < n; ++i)
printf("-1 ");
printf("\n");
return;
}
v[u[i].fi].push_back((i + 1));
v[u[i].se + 1].push_back(-(i + 1));
}
set<int> s;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < v[i].size(); ++j)
{
if (v[i][j] > 0)
s.insert(v[i][j] - 1);
else
{
if (s.find(-v[i][j] - 1) != s.end())
{
for (int i = 0; i < n; ++i)
printf("-1 ");
printf("\n");
return;
}
}
}
auto it = s.lower_bound(qry(0, n - 1, i, 1));
if (it == s.end())
{
for (int i = 0; i < n; ++i)
printf("-1 ");
printf("\n");
return;
}
ans[i] = *it;
s.erase(it);
}
for (int i = 0; i < n; ++i)
printf("%d ", ans[i]);
printf("\n");
}
int main()
{
#ifdef SOMETHING
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif // SOMETHING
//ios_base::sync_with_stdio(false), cin.tie(0);
solv();
return 0;
}
//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}
Compilation message
rmq.cpp: In function 'void solv()':
rmq.cpp:78:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < v[i].size(); ++j)
~~^~~~~~~~~~~~~
rmq.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~
rmq.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &l, &r, &y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
6 ms |
2664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
6 ms |
2664 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
7 ms |
2816 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
16 |
Correct |
7 ms |
2816 KB |
Output is correct |
17 |
Correct |
7 ms |
2816 KB |
Output is correct |
18 |
Correct |
7 ms |
2816 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
7 ms |
2816 KB |
Output is correct |
21 |
Correct |
7 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2688 KB |
Output is correct |
23 |
Correct |
6 ms |
2944 KB |
Output is correct |
24 |
Correct |
6 ms |
2688 KB |
Output is correct |
25 |
Correct |
6 ms |
2688 KB |
Output is correct |
26 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
6 ms |
2664 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
7 ms |
2816 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
16 |
Correct |
7 ms |
2816 KB |
Output is correct |
17 |
Correct |
7 ms |
2816 KB |
Output is correct |
18 |
Correct |
7 ms |
2816 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
7 ms |
2816 KB |
Output is correct |
21 |
Correct |
7 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2688 KB |
Output is correct |
23 |
Correct |
6 ms |
2944 KB |
Output is correct |
24 |
Correct |
6 ms |
2688 KB |
Output is correct |
25 |
Correct |
6 ms |
2688 KB |
Output is correct |
26 |
Correct |
6 ms |
2688 KB |
Output is correct |
27 |
Correct |
106 ms |
10016 KB |
Output is correct |
28 |
Correct |
96 ms |
10528 KB |
Output is correct |
29 |
Correct |
86 ms |
10180 KB |
Output is correct |
30 |
Correct |
109 ms |
10936 KB |
Output is correct |
31 |
Correct |
82 ms |
8692 KB |
Output is correct |
32 |
Correct |
91 ms |
8692 KB |
Output is correct |
33 |
Correct |
42 ms |
8728 KB |
Output is correct |
34 |
Correct |
34 ms |
7204 KB |
Output is correct |
35 |
Correct |
58 ms |
10604 KB |
Output is correct |
36 |
Correct |
47 ms |
5624 KB |
Output is correct |
37 |
Correct |
65 ms |
6008 KB |
Output is correct |
38 |
Correct |
28 ms |
7276 KB |
Output is correct |
39 |
Correct |
58 ms |
5624 KB |
Output is correct |
40 |
Correct |
6 ms |
2688 KB |
Output is correct |
41 |
Correct |
6 ms |
2688 KB |
Output is correct |