#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<ll, int>
#define fi first
#define se second
using namespace std;
const int N = 1e6+2;
const int M = 52;
const int mod = 1e9+7;
const ll base = 75;
const ll inf = 1e16;
int n, lab[N], t, c[N], h[N], m, a[N], b[N], k;
ll ans, d[N];
vector<int> adj[N], g[N];
vector<vector<int>> res;
vector<int> vi, cur;
string s;
bool vis[N];
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n&1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
void add(int& x, int y)
{
x += y;
if(x >= mod)x -= mod;
}
int findp(int u)
{
return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
}
void hop(int u, int v)
{
u = findp(u);
v = findp(v);
if(u == v)return;
if(lab[u] > lab[v])swap(u, v);
lab[u] += lab[v];
lab[v] = u;
}
struct BIT
{
int n;
vector<ll> fe;
BIT(){}
void init(int _n)
{
n = _n;
fe.resize(n+1, 0);
}
void reset()
{
fill(fe.begin(), fe.end(), 0);
}
void add(int id, int x)
{
for(; id <= n; id += id & -id)fe[id] += x;
}
ll get(int id)
{
ll total = 0;
for(; id; id -= id & -id)total += fe[id];
return total;
}
};
pll p[N];
ll ccw(pll x, pll y)
{
return x.se * y.fi - x.fi * y.se;
}
bool cmp(const pll& x, pll& y)
{
if((x.fi > 0) != (y.fi > 0))return x.fi < y.fi;
return ccw(x, y) > 0;
}
void sol()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
int j = lower_bound(vi.begin(), vi.end(), a[i]) - vi.begin();
if(j == vi.size())vi.pb(a[i]);
else vi[j] = a[i];
adj[j].pb(i);
}
m = vi.size();
for(int i = 0; i < m; i ++)reverse(adj[i].begin(), adj[i].end());
while(true)
{
if(k == 0)
{
if(adj[0].empty())break;
cur.pb(adj[0].back());
adj[0].pop_back();
++k;
}
else if(k == m)
{
res.pb(cur);
cur.clear();
k = 0;
}
else
{
while(!adj[k].empty() && adj[k].back() < cur.back())adj[k].pop_back();
if(adj[k].empty() || a[adj[k].back()] < a[cur.back()])
{
cur.pop_back();
--k;
}
else
{
cur.pb(adj[k].back());
adj[k].pop_back();
++k;
}
}
}
cout << res.size() <<" "<<m<<'\n';
while(!res.empty())
{
cur = res.back();
res.pop_back();
for(int j = 0; j < m; j ++)cout << cur[j] <<" ";
cout << '\n';
}
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int test = 1;
//cin >> test;
while(test -- > 0)sol();
return 0;
}
/*
1234
21
*/
Compilation message
Main.cpp: In function 'void sol()':
Main.cpp:93:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | if(j == vi.size())vi.pb(a[i]);
| ~~^~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:147:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
147 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:148:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
148 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47300 KB |
Output is correct |
2 |
Correct |
26 ms |
47172 KB |
Output is correct |
3 |
Correct |
26 ms |
47224 KB |
Output is correct |
4 |
Correct |
25 ms |
47308 KB |
Output is correct |
5 |
Correct |
24 ms |
47292 KB |
Output is correct |
6 |
Correct |
28 ms |
47308 KB |
Output is correct |
7 |
Correct |
22 ms |
47244 KB |
Output is correct |
8 |
Correct |
23 ms |
47288 KB |
Output is correct |
9 |
Correct |
24 ms |
47360 KB |
Output is correct |
10 |
Correct |
23 ms |
47284 KB |
Output is correct |
11 |
Correct |
25 ms |
47220 KB |
Output is correct |
12 |
Correct |
23 ms |
47300 KB |
Output is correct |
13 |
Correct |
26 ms |
47308 KB |
Output is correct |
14 |
Correct |
32 ms |
47272 KB |
Output is correct |
15 |
Correct |
25 ms |
47276 KB |
Output is correct |
16 |
Correct |
25 ms |
47280 KB |
Output is correct |
17 |
Correct |
23 ms |
47308 KB |
Output is correct |
18 |
Correct |
23 ms |
47320 KB |
Output is correct |
19 |
Correct |
22 ms |
47296 KB |
Output is correct |
20 |
Correct |
24 ms |
47240 KB |
Output is correct |
21 |
Correct |
23 ms |
47208 KB |
Output is correct |
22 |
Correct |
23 ms |
47280 KB |
Output is correct |
23 |
Correct |
23 ms |
47280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47300 KB |
Output is correct |
2 |
Correct |
26 ms |
47172 KB |
Output is correct |
3 |
Correct |
26 ms |
47224 KB |
Output is correct |
4 |
Correct |
25 ms |
47308 KB |
Output is correct |
5 |
Correct |
24 ms |
47292 KB |
Output is correct |
6 |
Correct |
28 ms |
47308 KB |
Output is correct |
7 |
Correct |
22 ms |
47244 KB |
Output is correct |
8 |
Correct |
23 ms |
47288 KB |
Output is correct |
9 |
Correct |
24 ms |
47360 KB |
Output is correct |
10 |
Correct |
23 ms |
47284 KB |
Output is correct |
11 |
Correct |
25 ms |
47220 KB |
Output is correct |
12 |
Correct |
23 ms |
47300 KB |
Output is correct |
13 |
Correct |
26 ms |
47308 KB |
Output is correct |
14 |
Correct |
32 ms |
47272 KB |
Output is correct |
15 |
Correct |
25 ms |
47276 KB |
Output is correct |
16 |
Correct |
25 ms |
47280 KB |
Output is correct |
17 |
Correct |
23 ms |
47308 KB |
Output is correct |
18 |
Correct |
23 ms |
47320 KB |
Output is correct |
19 |
Correct |
22 ms |
47296 KB |
Output is correct |
20 |
Correct |
24 ms |
47240 KB |
Output is correct |
21 |
Correct |
23 ms |
47208 KB |
Output is correct |
22 |
Correct |
23 ms |
47280 KB |
Output is correct |
23 |
Correct |
23 ms |
47280 KB |
Output is correct |
24 |
Correct |
27 ms |
47308 KB |
Output is correct |
25 |
Correct |
23 ms |
47308 KB |
Output is correct |
26 |
Correct |
23 ms |
47284 KB |
Output is correct |
27 |
Correct |
23 ms |
47300 KB |
Output is correct |
28 |
Correct |
24 ms |
47304 KB |
Output is correct |
29 |
Correct |
23 ms |
47308 KB |
Output is correct |
30 |
Correct |
24 ms |
47436 KB |
Output is correct |
31 |
Correct |
23 ms |
47292 KB |
Output is correct |
32 |
Correct |
23 ms |
47224 KB |
Output is correct |
33 |
Correct |
24 ms |
47308 KB |
Output is correct |
34 |
Correct |
24 ms |
47308 KB |
Output is correct |
35 |
Correct |
24 ms |
47288 KB |
Output is correct |
36 |
Correct |
24 ms |
47264 KB |
Output is correct |
37 |
Correct |
23 ms |
47316 KB |
Output is correct |
38 |
Correct |
24 ms |
47268 KB |
Output is correct |
39 |
Correct |
23 ms |
47240 KB |
Output is correct |
40 |
Correct |
30 ms |
47228 KB |
Output is correct |
41 |
Correct |
23 ms |
47280 KB |
Output is correct |
42 |
Correct |
23 ms |
47308 KB |
Output is correct |
43 |
Correct |
24 ms |
47312 KB |
Output is correct |
44 |
Correct |
23 ms |
47304 KB |
Output is correct |
45 |
Correct |
29 ms |
47308 KB |
Output is correct |
46 |
Correct |
24 ms |
47312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47300 KB |
Output is correct |
2 |
Correct |
26 ms |
47172 KB |
Output is correct |
3 |
Correct |
26 ms |
47224 KB |
Output is correct |
4 |
Correct |
25 ms |
47308 KB |
Output is correct |
5 |
Correct |
24 ms |
47292 KB |
Output is correct |
6 |
Correct |
28 ms |
47308 KB |
Output is correct |
7 |
Correct |
22 ms |
47244 KB |
Output is correct |
8 |
Correct |
23 ms |
47288 KB |
Output is correct |
9 |
Correct |
24 ms |
47360 KB |
Output is correct |
10 |
Correct |
23 ms |
47284 KB |
Output is correct |
11 |
Correct |
25 ms |
47220 KB |
Output is correct |
12 |
Correct |
23 ms |
47300 KB |
Output is correct |
13 |
Correct |
26 ms |
47308 KB |
Output is correct |
14 |
Correct |
32 ms |
47272 KB |
Output is correct |
15 |
Correct |
25 ms |
47276 KB |
Output is correct |
16 |
Correct |
25 ms |
47280 KB |
Output is correct |
17 |
Correct |
23 ms |
47308 KB |
Output is correct |
18 |
Correct |
23 ms |
47320 KB |
Output is correct |
19 |
Correct |
22 ms |
47296 KB |
Output is correct |
20 |
Correct |
24 ms |
47240 KB |
Output is correct |
21 |
Correct |
23 ms |
47208 KB |
Output is correct |
22 |
Correct |
23 ms |
47280 KB |
Output is correct |
23 |
Correct |
23 ms |
47280 KB |
Output is correct |
24 |
Correct |
27 ms |
47308 KB |
Output is correct |
25 |
Correct |
23 ms |
47308 KB |
Output is correct |
26 |
Correct |
23 ms |
47284 KB |
Output is correct |
27 |
Correct |
23 ms |
47300 KB |
Output is correct |
28 |
Correct |
24 ms |
47304 KB |
Output is correct |
29 |
Correct |
23 ms |
47308 KB |
Output is correct |
30 |
Correct |
24 ms |
47436 KB |
Output is correct |
31 |
Correct |
23 ms |
47292 KB |
Output is correct |
32 |
Correct |
23 ms |
47224 KB |
Output is correct |
33 |
Correct |
24 ms |
47308 KB |
Output is correct |
34 |
Correct |
24 ms |
47308 KB |
Output is correct |
35 |
Correct |
24 ms |
47288 KB |
Output is correct |
36 |
Correct |
24 ms |
47264 KB |
Output is correct |
37 |
Correct |
23 ms |
47316 KB |
Output is correct |
38 |
Correct |
24 ms |
47268 KB |
Output is correct |
39 |
Correct |
23 ms |
47240 KB |
Output is correct |
40 |
Correct |
30 ms |
47228 KB |
Output is correct |
41 |
Correct |
23 ms |
47280 KB |
Output is correct |
42 |
Correct |
23 ms |
47308 KB |
Output is correct |
43 |
Correct |
24 ms |
47312 KB |
Output is correct |
44 |
Correct |
23 ms |
47304 KB |
Output is correct |
45 |
Correct |
29 ms |
47308 KB |
Output is correct |
46 |
Correct |
24 ms |
47312 KB |
Output is correct |
47 |
Correct |
90 ms |
53828 KB |
Output is correct |
48 |
Correct |
98 ms |
54192 KB |
Output is correct |
49 |
Correct |
111 ms |
56512 KB |
Output is correct |
50 |
Correct |
204 ms |
63456 KB |
Output is correct |
51 |
Correct |
59 ms |
51008 KB |
Output is correct |
52 |
Correct |
271 ms |
104120 KB |
Output is correct |
53 |
Correct |
269 ms |
124540 KB |
Output is correct |
54 |
Correct |
255 ms |
71128 KB |
Output is correct |
55 |
Correct |
241 ms |
70984 KB |
Output is correct |
56 |
Correct |
30 ms |
47416 KB |
Output is correct |
57 |
Correct |
172 ms |
60332 KB |
Output is correct |
58 |
Correct |
58 ms |
50336 KB |
Output is correct |
59 |
Correct |
60 ms |
49800 KB |
Output is correct |
60 |
Correct |
162 ms |
60624 KB |
Output is correct |
61 |
Correct |
115 ms |
55916 KB |
Output is correct |
62 |
Correct |
26 ms |
47288 KB |
Output is correct |
63 |
Correct |
26 ms |
47292 KB |
Output is correct |
64 |
Correct |
27 ms |
47308 KB |
Output is correct |
65 |
Correct |
28 ms |
47300 KB |
Output is correct |
66 |
Correct |
34 ms |
47232 KB |
Output is correct |
67 |
Correct |
27 ms |
47292 KB |
Output is correct |
68 |
Correct |
29 ms |
47292 KB |
Output is correct |
69 |
Correct |
27 ms |
47232 KB |
Output is correct |