QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#352362 | #4425. Cake | ucup-team1209# | WA | 3424ms | 70036kb | C++20 | 1.4kb | 2024-03-13 10:28:49 | 2024-03-13 10:28:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,x,y) for (int i=(x);i>=(y);i--)
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
template<typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template<typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
void file() {
#ifdef zqj
freopen("a.in","r",stdin);
#endif
}
typedef long long ll;
#define sz 505050
int n;
int a[sz][2],b[sz][2];
int tr[sz];
void add(int x){while (x<=n) tr[x]++,x+=x&-x;}
int query(int x){int res=0;while (x) res+=tr[x],x-=x&-x;return res;}
void work() {
cin>>n;
rep(j,0,1) rep(i,1,n) cin>>a[i][j];
rep(j,0,1) rep(i,1,n) cin>>b[i][j];
rep(i,1,n) if (i&1) swap(a[i][0],a[i][1]),swap(b[i][0],b[i][1]);
map<ll,vector<int>>posb;
rep(i,1,n) {
ll y=1ll*b[i][0]*int(1e9+7)+b[i][1];
posb[y].push_back(i);
}
static int p[sz];
drep(i,n,1) {
ll x=1ll*a[i][0]*int(1e9+7)+a[i][1];
if (!posb[x].size()) return cout<<"-1\n",void();
p[i]=posb[x].back(); posb[x].pop_back();
}
ll ans=0;
rep(i,1,n) ans+=query(p[i]),add(p[i]);
rep(i,1,n) tr[i]=0;
cout<<ans<<'\n';
}
int main() {
file();
ios::sync_with_stdio(false),cin.tie(0);
int T; cin>>T;
while (T--) work();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 3424ms
memory: 70036kb
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:
124999750000 -1 0 62430704619
result:
wrong answer 1st lines differ - expected: '0', found: '124999750000'