比赛 |
国庆欢乐赛2 |
评测结果 |
TTTTTTTTTTTTTTTTTTTT |
题目名称 |
魔法卡片 |
最终得分 |
0 |
用户昵称 |
二乾五 |
运行时间 |
40.002 s |
代码语言 |
C++ |
内存使用 |
56.24 MiB |
提交时间 |
2025-10-04 11:38:03 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define foru(a,b,c) for(ll a=b;a<=c;a++)
ll n,m,q,ans;
vector<vector<ll> >a(1000005),b(1000005);
bool chose[1000005];
ll sum(ll l,ll r){
ll ssum=0;
set<ll>st;
foru(i,l,r){
if(chose[i]){
for(auto x:b[i]){
st.insert(x);
}
}else{
for(auto x:a[i]){
st.insert(x);
}
}
}
// cerr<<"#"<<endl;
for(auto x:st){
ssum+=x*x;
// cerr<<x<<" ";
}
// cerr<<endl;
return ssum;
}
void dfs(ll u,ll l,ll r){
if(u==r+1){
ans=max(ans,sum(l,r));
}else{
chose[u]=1;
dfs(u+1,l,r);
chose[u]=0;
dfs(u+1,l,r);
}
}
int main(){
freopen("magic.in" ,"r",stdin );
freopen("magic.out","w",stdout);
cin>>n>>m>>q;
foru(i,1,n){
ll tmp,x;
cin>>tmp;
map<ll,bool>mp;
foru(j,1,tmp){
cin>>x;
a[i].push_back(x);
mp[x]=1;
}
foru(j,1,m){
if(mp[j]!=1){
b[i].push_back(j);
}
}
}
// foru(i,1,n){
// cerr<<"#"<<i<<endl;
// for(auto x:a[i]){
// cerr<<x<<" ";
// }
// cerr<<endl;
// for(auto x:b[i]){
// cerr<<x<<" ";
// }
// cerr<<endl;
// }
foru(i,1,q){
ll l,r;
cin>>l>>r;
ans=0;
dfs(l,l,r);
cout<<ans<<endl;
}
return 0;
}