QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#64398 | #4425. Cake | Sa3tElSefr# | AC ✓ | 6451ms | 116764kb | C++23 | 2.4kb | 2022-11-24 19:12:51 | 2022-11-24 19:12:53 |
Judging History
answer
/// Brrrr Brrrr
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k): returns the number of elements in the set strictly less than k
// find_by_order(k): returns an iterator to the k-th element (zero-based) in the set
#define pb push_back
#define F first
#define S second
#define f(i, a, b) for(int i = a; i < b; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp(x,y) make_pair(x,y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll
using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;
const int N = 5e5+5, LG = 18, MOD = (119 << 23) + 1;
const long double PI = acos(-1);
const long double EPS = 1e-7;
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};
int grid1[2][N];
int grid2[2][N];
void doWork() {
int n;
cin >> n;
vector<int> go1[2], go2[2];
f(i,0,2)
f(j,0,n) cin >> grid1[i][j];
f(i,0,2)
f(j,0,n) cin >> grid2[i][j];
vector<vector<int>> go(n + 1);
map<ii, int> mp;
vector<int> cnt(n + 1);
int ptr = 0;
vector<int> vec;
for(int i = 0; i < n; i++) {
if(i&1)swap(grid1[0][i], grid1[1][i]);
int x = grid1[0][i], y = grid1[1][i];
if(!mp.count({x,y})) mp[{x,y}] = ++ptr;
go[mp[{x,y}]].pb(i);
}
for(int i = 0; i < n; i++) {
if(i&1)swap(grid2[0][i], grid2[1][i]);
int x = grid2[0][i], y = grid2[1][i];
if(cnt[mp[{x,y}]] >= go[mp[{x,y}]].size()) {
cout << "-1\n";
return;
}
vec.push_back(go[mp[{x,y}]][cnt[mp[{x,y}]]]);
cnt[mp[{x,y}]]++;
}
ordered_set st;
ll ans = 0;
for(int i = 0; i < n; i++) {
ans += i - st.order_of_key(vec[i]+1);
st.insert(vec[i]);
}
cout << ans << '\n';
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif // ONLINE_JUDGE
int t = 1;
cin >> t;
while (t--) {
doWork();
}
return 0;
}
///Look at my code ya codeomk
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5274ms
memory: 116736kb
input:
4 500000 471518156 319758862 812815356 520822448 129241996 461169933 796713727 608641317 281180101 953966756 749634941 274104949 996181952 88142916 998544672 125597509 991731126 974767231 338911715 674197249 167602044 682799026 226927279 703198907 216742488 8185420 94921423 690039818 859329736 45428...
output:
0 -1 124999750000 62569045381
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 6451ms
memory: 116764kb
input:
4 500000 413978977 447850293 802546055 289227062 321812178 97254226 380555063 167654142 874843339 349071516 10868808 93093321 996630037 33169052 99312773 335065051 278187197 94810404 643530967 947474510 63047182 573006260 8470509 116477506 251504796 899920047 806158195 452300674 859769748 489596554 ...
output:
62623368052 62486676013 62520737719 62506121292
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 1524ms
memory: 11160kb
input:
9082 7 714942297 703160828 709363739 23094554 461254804 159017923 666590460 196100940 70571239 755082029 321718821 55663261 378527017 335969190 321718821 335969190 70571239 755082029 378527017 55663261 714942297 23094554 666590460 703160828 709363739 159017923 461254804 196100940 5 2 1 1 2 1 2 1 2 2...
output:
13 5 0 -1 0 2 10 2 0 5 0 10 15 1 2336 -1 1 -1 -1 4 -1 15 0 9 45 15 3 4 0 11 -1 -1 10 -1 18 10 0 3 1 -1 0 1 0 5 -1 16 -1 -1 -1 15 -1 307294 -1 7 0 0 -1 -1 -1 0 2210 3 1 16 -1 -1 0 -1 0 0 5 5 10 3 0 -1 21 0 7 3 0 32308741 -1 20 -1 0 1 -1 9 6 2249 0 -1 0 55236 2265 1 12 -1 -1 29 0 -1 20 0 2 0 0 1 -1 0 ...
result:
ok 9082 lines
Extra Test:
score: 0
Extra Test Passed