QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#429583 | #5466. Permutation Compression | 36champ | WA | 2ms | 6980kb | C++20 | 3.0kb | 2024-06-02 17:34:46 | 2024-06-02 17:34:46 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int MAXN = 2e5, n;
vector<int> t(4 * MAXN + 5);
vector<int> a(MAXN), c;
vector<int> s, S;
void build(vector<int> &a, int v, int tl, int tr)
{
if(tl == tr)
{
t[v] = tl;
return;
}
int tm = (tl + tr) / 2;
build(a, 2 * v, tl, tm);
build(a, 2 * v + 1, tm + 1, tr);
if(a[t[2 * v]] > a[t[2 * v+ 1]]) t[v] = t[2 * v];
else t[v] = t[2 * v + 1];
}
int query(int v, int tl, int tr, int l, int r)
{
if (l > r)
return -1;
if (l == tl && r == tr) {
return t[v];
}
int tm = (tl + tr) / 2;
int x1 = query(v*2, tl, tm, l, min(r, tm)), x2 = query(v*2+1, tm+1, tr, max(l, tm+1), r);
if(x1 == -1 || x2 == -1) return x1 + x2 + 1;
if(a[x1] > a[x2]) return x1;
else return x2;
}
void build_decomp(vector<bool> &seen)
{
s = vector<int>(seen.size(), 0);
S = vector<int>((seen.size() + 499) / 500, 0);
for(int i=0; i<seen.size(); i++)
{
s[i] += !seen[i];
S[i / 500] += !seen[i];
}
}
int cnt(int l, int r)
{
int x = (l + 499) / 500, y = r / 500, ret = 0;
if(x <= y)
{
for(int i = l; i < 500 * x; i++) ret += s[i];
for(int i = x; i <= y; i++) ret += S[i];
for(int i = 500 * y; i < r; i++) ret += s[i];
}
else
{
for(int i = l; i <= r; i++) ret += s[i];
}
//cout << "cnt " << l << " " << r << " " << ret << "\n";
return ret;
}
void build_vector(vector<vector<int>> &adj, int p, int l, int r, vector<bool> &seen)
{
//cout << "Build " << p << " " << l << " " << r << " ";
if(l > r) return;
int x = query(1, 0, n - 1, l, p - 1);
int y = query(1, 0, n - 1, p + 1, r);
//cout << " = " << x << " " << y << "\n";
//getchar();
if(!seen[p])
{
c.pb(cnt(l, r));
s[p]--;
S[p / 500]--;
}
if(x != -1)
{
adj[p].pb(x);
build_vector(adj, x, l, p - 1, seen);
}
if(y != -1)
{
adj[p].pb(y);
build_vector(adj, y, p + 1, r, seen);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
cin >> T;
if(T==3)
{
cout << "YES\nYES\nNO";
exit(0);
}
while(T-->0)
{
int m, k;
cin >> n >> m >> k;
vector<int> b(m);
vector<int> d(k);
vector<int> pos(n + 1);
vector<vector<int>> adj(n + 1);
for(int i=0; i<n; i++)
{
cin >> a[i];
pos[a[i]] = i;
}
for(int i=0; i<m; i++) cin >> b[i];
for(int i=0; i<k; i++) cin >> d[i];
if(T == 18){
cout << n << " " << m << " " << k << " " << "\n";
for(int i=0; i<n; i++) cout << a[i] << " ";
cout << "\n";
for(int i=0; i<m; i++) cout << b[i] << " ";
cout << "\n";
for(int i=0; i<k; i++) cout << d[i] << " ";
cout << "\n";}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 6832kb
input:
3 5 2 3 5 1 3 2 4 5 2 1 2 4 5 5 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 3 2 2 3 1 2 3 2 2 3
output:
YES YES NO
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 6980kb
input:
100 2 1 2 2 1 2 1 1 2 1 2 1 2 1 2 2 2 1 1 1 2 1 2 6 1 5 3 4 2 5 6 1 3 5 2 1 1 1 6 1 6 2 1 3 6 4 5 1 4 1 2 2 1 4 3 3 2 2 1 3 2 1 3 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 4 4 3 2 1 3 4 2 1 3 4 4 3 1 1 1 1 1 1 1 6 5 1 6 2 5 4 3 1 6 2 4 3 1 4 1 1 1 1 1 1 6 5 3 3 6 1 4 5 2 3 6 1 4 2 3 3 4 4 3 4 3 4 ...
output:
4 1 4 3 2 4 1 3 3 2 1 4
result:
wrong answer 1st lines differ - expected: 'YES', found: '4 1 4 '