This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |