QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#872714 | #8613. Cardinality | ucup-team1134# | RE | 0ms | 9216kb | C++23 | 1.9kb | 2025-01-26 03:54:22 | 2025-01-26 03:54:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;
const int M=12500;
bitset<M> dp[350005];
pii mae[550005];
int kaku[550005];
bitset<M> solve(int x){
if(kaku[x]!=-1) return dp[kaku[x]];
else return solve(mae[x].fi)|solve(mae[x].se);
}
int main(){
memset(kaku,-1,sizeof(kaku));
int N,Q;cin>>N>>Q;
for(int i=0;i<N;i++){
dp[i][i/4]=true;
kaku[i]=i;
}
int tim=N;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
for(int q=0;q<Q;q+=50){
vii que;
for(int i=q;i<min(Q,q+50);i++){
int a,b;cin>>a>>b;a--;b--;
que.pb(mp(a,b));
}
for(int i=q;i<min(Q,q+50);i++){
auto [a,b]=que[i-q];
auto res=solve(a)|solve(b);
cout<<res.count()*2<<"\n";
int t=rng()&1;
if(t){
dp[tim]=res;
kaku[i]=tim;tim++;
}else{
mae[i]=mp(a,b);
}
}
cout<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9216kb
input:
4 5 1 2 2 3 5 6 6 7 4 7
output:
2 2 2 2 2
result:
ok
Test #2:
score: -100
Runtime Error
input:
10 100 9 2 9 10 5 1 6 6 13 14 3 4 3 8 8 4 16 5 14 2 8 13 14 9 6 17 15 11 24 7 24 20 1 26 14 27 6 18 14 14 15 11 14 25 8 11 7 30 3 11 12 3 6 19 29 36 30 9 38 6 2 28 12 40 33 25 20 42 17 30 23 1 34 41 41 36 7 18 39 45 32 4 30 21 46 26 12 39 42 42 46 48 31 54 16 37 42 4 27 34
output:
4 2 4 2 2 4 4 2 2 4 4 4 4 4 4 2 2 4 4 4 4 4 4 4 4 6 4 2 4 4 4 4 4 4 6 4 4 4 4 4 6 6 6 6 6 2 4 6 6 4