QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#252352 | #4425. Cake | oogerbooger# | AC ✓ | 3635ms | 109248kb | C++14 | 3.3kb | 2023-11-15 18:42:07 | 2023-11-15 18:42:08 |
Judging History
answer
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define INF 1e9
#define INFl 1e18
#define all(x) x.begin(), x.end()
#define sajz(x) (int)x.size()
#define pb push_back
#define se second
#define fi first
#define yes puts("YES")
#define no puts("NO")
#define erase_duplicates(x) {sort(all(x));(x).resize(distance((x).begin(), unique(all(x))));}
using namespace std;
//using namespace __gnu_pbds;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef set<int> si;
typedef multiset<int> msi;
typedef long double ld;
//typedef cc_hash_table<int, int, hash<int>> ht;
int base;
vi t;
void add(int idx, int val) {
int cur = base+idx;
while(cur > 0) {
t[cur] += val;
cur /= 2;
}
}
int query(int node, int ns, int ne, int qs, int qe) {
if(ne < qs || qe < ns) return 0;
if(qs <= ns && ne <= qe) return t[node];
int mid = (ns+ne)/2;
int left = query(2*node, ns, mid, qs, qe);
int right = query(2*node+1, mid+1, ne, qs, qe);
return left+right;
}
void test_case() {
int n;
cin >> n;
vector<pii> a(n), b(n);
for(int i = 0; i < n; i++) cin >> a[i].fi;
for(int i = 0; i < n; i++) cin >> a[i].se;
for(int i = 0; i < n; i++) cin >> b[i].fi;
for(int i = 0; i < n; i++) cin >> b[i].se;
map<pair<int,int>,set<int>> mp;
for(int i = 0; i < n; i++) {
if(i%2==0) {
mp[a[i]].insert(i);
} else {
pii cur = {a[i].se,a[i].fi};
mp[cur].insert(i);
}
}
vi p(n);
bool f = false;
for(int i = 0; i < n && !f; i++) {
pii cur;
if(i%2 == 0) cur = b[i];
else cur = {b[i].se, b[i].fi};
auto it = mp[cur].lower_bound(0);
if(it == mp[cur].end()) f = true;
else {
p[i] = *it;
mp[cur].erase(*it);
}
}
if(f) {
cout << "-1\n";
return;
}
base = 1 << (int)(log2(n)+1);
t.assign(2*base, 0);
int ans = 0;
for(int i = 0; i < n; i++) {
int v = p[i];
ans += query(1, 0, base-1, v, base-1);
add(v, 1);
}
cout << ans << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
int tc=1;
cin >> tc;
while(tc--)test_case();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3018ms
memory: 109132kb
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: 3635ms
memory: 109248kb
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: 973ms
memory: 5704kb
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