#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;
}
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 |
47288 KB |
Output is correct |
2 |
Correct |
22 ms |
47204 KB |
Output is correct |
3 |
Correct |
22 ms |
47176 KB |
Output is correct |
4 |
Correct |
24 ms |
47240 KB |
Output is correct |
5 |
Correct |
22 ms |
47208 KB |
Output is correct |
6 |
Correct |
22 ms |
47216 KB |
Output is correct |
7 |
Correct |
25 ms |
47204 KB |
Output is correct |
8 |
Correct |
23 ms |
47300 KB |
Output is correct |
9 |
Correct |
23 ms |
47284 KB |
Output is correct |
10 |
Correct |
22 ms |
47308 KB |
Output is correct |
11 |
Correct |
24 ms |
47292 KB |
Output is correct |
12 |
Correct |
23 ms |
47280 KB |
Output is correct |
13 |
Correct |
24 ms |
47308 KB |
Output is correct |
14 |
Correct |
26 ms |
47296 KB |
Output is correct |
15 |
Correct |
23 ms |
47292 KB |
Output is correct |
16 |
Correct |
23 ms |
47292 KB |
Output is correct |
17 |
Correct |
24 ms |
47308 KB |
Output is correct |
18 |
Correct |
24 ms |
47288 KB |
Output is correct |
19 |
Correct |
23 ms |
47300 KB |
Output is correct |
20 |
Correct |
24 ms |
47268 KB |
Output is correct |
21 |
Correct |
23 ms |
47308 KB |
Output is correct |
22 |
Correct |
23 ms |
47240 KB |
Output is correct |
23 |
Correct |
24 ms |
47272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47288 KB |
Output is correct |
2 |
Correct |
22 ms |
47204 KB |
Output is correct |
3 |
Correct |
22 ms |
47176 KB |
Output is correct |
4 |
Correct |
24 ms |
47240 KB |
Output is correct |
5 |
Correct |
22 ms |
47208 KB |
Output is correct |
6 |
Correct |
22 ms |
47216 KB |
Output is correct |
7 |
Correct |
25 ms |
47204 KB |
Output is correct |
8 |
Correct |
23 ms |
47300 KB |
Output is correct |
9 |
Correct |
23 ms |
47284 KB |
Output is correct |
10 |
Correct |
22 ms |
47308 KB |
Output is correct |
11 |
Correct |
24 ms |
47292 KB |
Output is correct |
12 |
Correct |
23 ms |
47280 KB |
Output is correct |
13 |
Correct |
24 ms |
47308 KB |
Output is correct |
14 |
Correct |
26 ms |
47296 KB |
Output is correct |
15 |
Correct |
23 ms |
47292 KB |
Output is correct |
16 |
Correct |
23 ms |
47292 KB |
Output is correct |
17 |
Correct |
24 ms |
47308 KB |
Output is correct |
18 |
Correct |
24 ms |
47288 KB |
Output is correct |
19 |
Correct |
23 ms |
47300 KB |
Output is correct |
20 |
Correct |
24 ms |
47268 KB |
Output is correct |
21 |
Correct |
23 ms |
47308 KB |
Output is correct |
22 |
Correct |
23 ms |
47240 KB |
Output is correct |
23 |
Correct |
24 ms |
47272 KB |
Output is correct |
24 |
Correct |
23 ms |
47224 KB |
Output is correct |
25 |
Correct |
24 ms |
47240 KB |
Output is correct |
26 |
Correct |
24 ms |
47204 KB |
Output is correct |
27 |
Correct |
23 ms |
47220 KB |
Output is correct |
28 |
Correct |
23 ms |
47320 KB |
Output is correct |
29 |
Correct |
25 ms |
47368 KB |
Output is correct |
30 |
Correct |
24 ms |
47316 KB |
Output is correct |
31 |
Correct |
24 ms |
47308 KB |
Output is correct |
32 |
Correct |
25 ms |
47252 KB |
Output is correct |
33 |
Correct |
24 ms |
47420 KB |
Output is correct |
34 |
Correct |
23 ms |
47308 KB |
Output is correct |
35 |
Correct |
23 ms |
47312 KB |
Output is correct |
36 |
Correct |
24 ms |
47320 KB |
Output is correct |
37 |
Correct |
24 ms |
47304 KB |
Output is correct |
38 |
Correct |
23 ms |
47268 KB |
Output is correct |
39 |
Correct |
24 ms |
47280 KB |
Output is correct |
40 |
Correct |
22 ms |
47304 KB |
Output is correct |
41 |
Correct |
23 ms |
47312 KB |
Output is correct |
42 |
Correct |
24 ms |
47204 KB |
Output is correct |
43 |
Correct |
23 ms |
47308 KB |
Output is correct |
44 |
Correct |
24 ms |
47224 KB |
Output is correct |
45 |
Correct |
23 ms |
47296 KB |
Output is correct |
46 |
Correct |
23 ms |
47292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47288 KB |
Output is correct |
2 |
Correct |
22 ms |
47204 KB |
Output is correct |
3 |
Correct |
22 ms |
47176 KB |
Output is correct |
4 |
Correct |
24 ms |
47240 KB |
Output is correct |
5 |
Correct |
22 ms |
47208 KB |
Output is correct |
6 |
Correct |
22 ms |
47216 KB |
Output is correct |
7 |
Correct |
25 ms |
47204 KB |
Output is correct |
8 |
Correct |
23 ms |
47300 KB |
Output is correct |
9 |
Correct |
23 ms |
47284 KB |
Output is correct |
10 |
Correct |
22 ms |
47308 KB |
Output is correct |
11 |
Correct |
24 ms |
47292 KB |
Output is correct |
12 |
Correct |
23 ms |
47280 KB |
Output is correct |
13 |
Correct |
24 ms |
47308 KB |
Output is correct |
14 |
Correct |
26 ms |
47296 KB |
Output is correct |
15 |
Correct |
23 ms |
47292 KB |
Output is correct |
16 |
Correct |
23 ms |
47292 KB |
Output is correct |
17 |
Correct |
24 ms |
47308 KB |
Output is correct |
18 |
Correct |
24 ms |
47288 KB |
Output is correct |
19 |
Correct |
23 ms |
47300 KB |
Output is correct |
20 |
Correct |
24 ms |
47268 KB |
Output is correct |
21 |
Correct |
23 ms |
47308 KB |
Output is correct |
22 |
Correct |
23 ms |
47240 KB |
Output is correct |
23 |
Correct |
24 ms |
47272 KB |
Output is correct |
24 |
Correct |
23 ms |
47224 KB |
Output is correct |
25 |
Correct |
24 ms |
47240 KB |
Output is correct |
26 |
Correct |
24 ms |
47204 KB |
Output is correct |
27 |
Correct |
23 ms |
47220 KB |
Output is correct |
28 |
Correct |
23 ms |
47320 KB |
Output is correct |
29 |
Correct |
25 ms |
47368 KB |
Output is correct |
30 |
Correct |
24 ms |
47316 KB |
Output is correct |
31 |
Correct |
24 ms |
47308 KB |
Output is correct |
32 |
Correct |
25 ms |
47252 KB |
Output is correct |
33 |
Correct |
24 ms |
47420 KB |
Output is correct |
34 |
Correct |
23 ms |
47308 KB |
Output is correct |
35 |
Correct |
23 ms |
47312 KB |
Output is correct |
36 |
Correct |
24 ms |
47320 KB |
Output is correct |
37 |
Correct |
24 ms |
47304 KB |
Output is correct |
38 |
Correct |
23 ms |
47268 KB |
Output is correct |
39 |
Correct |
24 ms |
47280 KB |
Output is correct |
40 |
Correct |
22 ms |
47304 KB |
Output is correct |
41 |
Correct |
23 ms |
47312 KB |
Output is correct |
42 |
Correct |
24 ms |
47204 KB |
Output is correct |
43 |
Correct |
23 ms |
47308 KB |
Output is correct |
44 |
Correct |
24 ms |
47224 KB |
Output is correct |
45 |
Correct |
23 ms |
47296 KB |
Output is correct |
46 |
Correct |
23 ms |
47292 KB |
Output is correct |
47 |
Correct |
92 ms |
53828 KB |
Output is correct |
48 |
Correct |
91 ms |
54168 KB |
Output is correct |
49 |
Correct |
108 ms |
56656 KB |
Output is correct |
50 |
Correct |
174 ms |
63576 KB |
Output is correct |
51 |
Correct |
62 ms |
51012 KB |
Output is correct |
52 |
Correct |
265 ms |
104144 KB |
Output is correct |
53 |
Correct |
282 ms |
124544 KB |
Output is correct |
54 |
Correct |
225 ms |
71044 KB |
Output is correct |
55 |
Correct |
207 ms |
71036 KB |
Output is correct |
56 |
Correct |
23 ms |
47428 KB |
Output is correct |
57 |
Correct |
152 ms |
60400 KB |
Output is correct |
58 |
Correct |
52 ms |
50240 KB |
Output is correct |
59 |
Correct |
46 ms |
49804 KB |
Output is correct |
60 |
Correct |
145 ms |
60580 KB |
Output is correct |
61 |
Correct |
105 ms |
55920 KB |
Output is correct |
62 |
Correct |
23 ms |
47308 KB |
Output is correct |
63 |
Correct |
23 ms |
47308 KB |
Output is correct |
64 |
Correct |
23 ms |
47308 KB |
Output is correct |
65 |
Correct |
23 ms |
47292 KB |
Output is correct |
66 |
Correct |
24 ms |
47272 KB |
Output is correct |
67 |
Correct |
24 ms |
47196 KB |
Output is correct |
68 |
Correct |
23 ms |
47200 KB |
Output is correct |
69 |
Correct |
25 ms |
47256 KB |
Output is correct |