QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#408169 | #6886. Simple Set Problem | xuzhihaodedie# | AC ✓ | 524ms | 28128kb | C++20 | 1.1kb | 2024-05-09 19:12:07 | 2024-05-09 19:12:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define lson 2*p
#define rson 2*p+1
#define x first
#define y second
//#define endl "\n"
constexpr int N=2e6+10;
constexpr int mod=998244353;
int n,m,cnt;
PII p[N];
void solve() {
cin>>n;
cnt=0;
for(int i=1;i<=n;i++) {
int k;
cin>>k;
for(int j=1;j<=k;j++) {
int x;
cin>>x;
p[++cnt]={x,i};
}
}
sort(p+1,p+cnt+1);
int j=cnt;
vector<int> num(n+10,0);
int sum=1;
num[p[cnt].y]++;
int ans=1e18;
for(int i=cnt;i>=1;i--) {
while(j-1>=1&&sum<n) {
j--;
num[p[j].y]++;
if(num[p[j].y]==1) sum++;
}
if(sum==n) {
ans=min(ans,p[i].x-p[j].x);
//cout<<i<<" "<<j<<" "<<p[i].x-p[j].x<<endl;
}
num[p[i].y]--;
if(!num[p[i].y]) sum--;
}
cout<<ans<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T=1;
cin>>T;
while(T--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 524ms
memory: 28128kb
input:
10018 1 5 -247462786 -97914904 849160785 -951926514 -829935728 7 72 8382969 -3251289 -63130380 -590108505 -798189380 -140833313 -626464256 136468139 -711222365 500861930 -459837972 914918723 186793042 872925162 -335485808 641571163 -314777234 -520573290 -894124702 618889116 2700292 -714868427 -34346...
output:
0 1800402714 860165806 487641037 229279918 238532335 392707612 456994871 256099628 1023121975 4986247 753213024 0 1289600751 598093746 55025093 95257568 145430738 34342513 0 157895624 789721360 232287715 1817496622 439049782 777966568 29118927 1671939338 1048279188 42073227 642353647 61747459 302989...
result:
ok 10018 lines