QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#87173 | #4406. 独立集问题 | johnsonloy_x | 0 | 0ms | 0kb | C++14 | 2.6kb | 2023-03-11 21:01:23 | 2023-03-11 21:01:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
const int maxn = 1e6+10;
const int inf = 1e18;
namespace IO{
void openfile(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
}
int add(int x,int y){
x+=y;
if(x>=mod)
x-=mod;
return x;
}
int sub(int x,int y){
x-=y;
if(x<0)
x+=mod;
return x;
}
inline int read(){
int x = 0,f = 0;
char c = getchar();
while(!isdigit(c))
f|=c=='-',c = getchar();
while(isdigit(c))
x = x*10+c-'0',c = getchar();
if(f)x = -x;
return x;
}
}
using namespace IO;
int n,m,k;
int p[maxn];
struct node{
int p,i,v;
bool operator<(const node& b)const{
return v>b.v;
}
};
struct nod{
int x,y,z,v;
bool operator<(const nod& b)const{
return v>b.v;
}
};
struct t1{
vector<int>va,num;
int l,r,n;
priority_queue<nod>q;
void calc(int now){
if(now<num.size())return;
if(q.empty()){
num.push_back(inf);
return;
}
nod u = q.top();
q.pop();
num.push_back(u.v);
if(u.z==n&&u.x+1==u.y&&u.y+1<=r)
q.push({u.x+1,u.y+1,u.z,u.v+va[u.y+1]});
if(u.y>=1&&u.y+1<=u.z)
q.push({u.x,u.y+1,u.z,u.v-va[u.y]+va[u.y+1]});
if(u.x&&u.x+1<u.y)
q.push({u.x-1,u.x+1,u.y-1,u.v-va[u.x]+va[u.x+1]});
}
void init(){
sort(va.begin(),va.end());
n = va.size() - 1,r = min(r,n);
if(l>n){
num.push_back(inf);
num.push_back(inf);
return;
}
int ans = 0;
for(int i=0;i<=l;i++)
ans+=va[i];
q.push({l-1,l,n,ans});
calc(0),calc(1);
}
}t[maxn];
priority_queue<node>q;
bool cmp(int x,int y){
return t[x].num[1] - t[x].num[0]<t[y].num[1] - t[y].num[0];
}
signed main(){
openfile();
n = read(),m = read(),k = read();
for(int i=1;i<=m;i++)
t[i].va.push_back(0);
for(int i=1;i<=n;i++){
int a = read(),c = read();
t[a].va.push_back(c);
}
int now = 0;
for(int i=1;i<=m;i++){
t[i].l = read(),t[i].r = read();
t[i].init(),p[i] = i;
now+=t[i].num[0];
now = min(now,inf);
}
q.push({0,0,now});
// cout<<now<<endl;
sort(p+1,p+1+m,cmp);
now = 0;
while(now<k&&!q.empty()){
node u = q.top();
q.pop();
if(u.v>=1e18)break;
now++;
printf("%lld\n",u.v);
if(u.p<m&&u.p>=1&&u.i==1)
q.push({u.p+1,1,u.v-t[p[u.p]].num[1]+t[p[u.p]].num[0]+t[p[u.p+1]].num[1]-t[p[u.p+1]].num[0]});
if(u.p<m)
q.push({u.p+1,1,u.v-t[p[u.p+1]].num[0]+t[p[u.p+1]].num[1]});
if(u.p>=1){
t[p[u.p]].calc(u.i+1);
q.push({u.p,u.i+1,u.v - t[p[u.p]].num[u.i]+t[p[u.p]].num[u.i+1]});
}
}
for(int i=now+1;i<=k;i++)
puts("-1");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
351493 -641495974 -401868912 -864400429 35718599 -579296290 767835327 149511992 -246228754 649472235 893048442 -292675192 -788090312 -578172296 -62289673 196890164 -120059197 -452848333 -216788131 -604555771 -240241020 376984486 -407661514 -107574590 -461679558 -470560314 -583391402 -991686079 76956...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #21:
score: 0
Runtime Error
input:
351493 915594742 688454502 456077914 208864399 625937959 102483811 538999077 529481828 400375958 387560315 83710527 83424975 330114353 684812426 68052931 28849220 295907801 535129167 967891325 124069427 644256858 757666812 558755455 178666038 177054898 795236216 848264282 669310447 328353372 3681163...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #41:
score: 0
Runtime Error
input:
7 247522519 398923496 -976223527 806215585 -937536479 -130552271 90576461 1 2 1 2 5 5
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%