记录编号 |
597496 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
魔法卡片 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
5.595 s |
提交时间 |
2024-11-28 15:34:45 |
内存使用 |
54.24 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,ll>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 1e6+10;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n,m,q,B;
ll sum,f[N],now[N];
vector<int>a[N];
vector<ll>s[N];
int main(){
freopen("magic.in","r",stdin);
freopen("magic.out","w",stdout);
n = read(),m = read(),q = read();
B = ceil(log2(m));
for(int i = 1;i <= n;i++){
int x = read();
a[i].pb(0);
for(int j = 1;j <= m;j++)a[i].pb(0);
for(int j = 1;j <= x;j++){
int w = read();
a[i][w] = 1;
}
}
//2^B = m
for(int i = 1;i <= m;i++)sum += (ll)i * i;
for(int i = 1;i <= n;i++){
s[i].pb(0);
for(int j = 1;j <= m;j++)now[j] = 0;
for(int j = i;j <= i + B - 1 && j <= n;j++){
for(int k = 1;k <= m;k++)now[k] = (now[k] << 1) | a[j][k],f[now[k]] += (ll)k * k;
ll mi = sum;
for(int k = 0;k < (1ll << (j-i+1));k++)mi = min(mi,f[k]),f[k] = 0;
s[i].pb(sum - mi);
}
}
for(int i = 1;i <= q;i++){
int l = read(),r = read();
if(r - l + 1 > B)printf("%lld\n",sum);
else printf("%lld\n",s[l][r-l+1]);
}
return 0;
}