QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#420038#8370. T3by_chanceCompile Error//C++143.3kb2024-05-24 14:11:442024-05-24 14:11:46

Judging History

你现在查看的是最新测评结果

  • [2024-05-24 14:11:46]
  • 评测
  • [2024-05-24 14:11:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,m,a[N],b[N],va,vb;
ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
int calc(ll x,ll y,ll lim,ll op){
    ll res=0;
    if(ca[x]>=y)res+=x*y;else res+=pa[y]*y+sa[x]-sa[pa[y]];
    if(cb[y+1]>=n-x)res+=(n-x)*(m-y);
    else res+=(m-pb[n-x]+1)*(n-x)+sb[y+1]-sb[pb[n-x]];
    if(op)res-=(va<=x&&vb<=y&&a[va]+b[vb]<=lim),
          res-=(va>x&&vb>y&&a[va]+b[vb]>lim);
    return res;
}
bool check(int lim){
    int p=m;
    for(int i=1;i<=n;i++){
        while(p&&a[i]+b[p]>lim)pa[p]=i-1,--p;
        sa[i]=sa[i-1]+(ca[i]=p);
    }
    while(p)pa[p]=n,--p;
    p=1;cb[m+1]=n+1;pb[n+1]=m+1;
    for(int i=m;i>=1;i--){
        while(p<=n&&a[p]+b[i]<=lim)pb[n-p+1]=i+1,++p;
        sb[i]=sb[i+1]+(cb[i]=n-p+1);
    }
    while(p<=n)pb[n-p+1]=1,++p;
    int res1=sb[1],res2=sb[1]-(a[va]+b[vb]>lim);
    for(int i=1,p1=1,p2=1;i<=n;i++){
        while(p1<m&&calc(i,p1,lim,0)<=calc(i,p1+1,lim,0))++p1;
        while(p2<m&&calc(i,p2,lim,1)<=calc(i,p2+1,lim,1))++p2;
        res1=max(res1,calc(i,p1,lim,0));res2=max(res2,calc(i,p2,lim,1));
    }
    return res1==res2;
}
int main(){
    // freopen("chess.in","r",stdin);
    // freopen("chess.out","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",a+i);va=a[1];
    for(int i=1;i<=m;i++)scanf("%d",b+i);vb=b[1];
    sort(a+1,a+n+1);va=lower_bound(a+1,a+n+1,va)-a;
    sort(b+1,b+m+1);vb=lower_bound(b+1,b+m+1,vb)-b;
    int L=0,R=a[va]+b[vb];
    while(L<R){
        int mid=(L+R)>>1;
        if(check(mid))R=mid;else L=mid+1;
    }
    printf("%d\n",R);
    return 0;
}#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,m,a[N],b[N],va,vb;
ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
int calc(ll x,ll y,ll lim,ll op){
    ll res=0;
    if(ca[x]>=y)res+=x*y;else res+=pa[y]*y+sa[x]-sa[pa[y]];
    if(cb[y+1]>=n-x)res+=(n-x)*(m-y);
    else res+=(m-pb[n-x]+1)*(n-x)+sb[y+1]-sb[pb[n-x]];
    if(op)res-=(va<=x&&vb<=y&&a[va]+b[vb]<=lim),
          res-=(va>x&&vb>y&&a[va]+b[vb]>lim);
    return res;
}
bool check(int lim){
    int p=m;
    for(int i=1;i<=n;i++){
        while(p&&a[i]+b[p]>lim)pa[p]=i-1,--p;
        sa[i]=sa[i-1]+(ca[i]=p);
    }
    while(p)pa[p]=n,--p;
    p=1;cb[m+1]=n+1;pb[n+1]=m+1;
    for(int i=m;i>=1;i--){
        while(p<=n&&a[p]+b[i]<=lim)pb[n-p+1]=i+1,++p;
        sb[i]=sb[i+1]+(cb[i]=n-p+1);
    }
    while(p<=n)pb[n-p+1]=1,++p;
    int res1=sb[1],res2=sb[1]-(a[va]+b[vb]>lim);
    for(int i=1,p1=1,p2=1;i<=n;i++){
        while(p1<m&&calc(i,p1,lim,0)<=calc(i,p1+1,lim,0))++p1;
        while(p2<m&&calc(i,p2,lim,1)<=calc(i,p2+1,lim,1))++p2;
        res1=max(res1,calc(i,p1,lim,0));res2=max(res2,calc(i,p2,lim,1));
    }
    return res1==res2;
}
int main(){
    // freopen("chess.in","r",stdin);
    // freopen("chess.out","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",a+i);va=a[1];
    for(int i=1;i<=m;i++)scanf("%d",b+i);vb=b[1];
    sort(a+1,a+n+1);va=lower_bound(a+1,a+n+1,va)-a;
    sort(b+1,b+m+1);vb=lower_bound(b+1,b+m+1,vb)-b;
    int L=0,R=a[va]+b[vb];
    while(L<R){
        int mid=(L+R)>>1;
        if(check(mid))R=mid;else L=mid+1;
    }
    printf("%d\n",R);
    return 0;
}

詳細信息

answer.code:52:2: error: stray ‘#’ in program
   52 | }#include<bits/stdc++.h>
      |  ^
answer.code:52:3: error: ‘include’ does not name a type
   52 | }#include<bits/stdc++.h>
      |   ^~~~~~~
answer.code:55:11: error: redefinition of ‘const int N’
   55 | const int N=2e5+5;
      |           ^
answer.code:4:11: note: ‘const int N’ previously defined here
    4 | const int N=2e5+5;
      |           ^
answer.code:56:5: error: redefinition of ‘int n’
   56 | int n,m,a[N],b[N],va,vb;
      |     ^
answer.code:5:5: note: ‘int n’ previously declared here
    5 | int n,m,a[N],b[N],va,vb;
      |     ^
answer.code:56:7: error: redefinition of ‘int m’
   56 | int n,m,a[N],b[N],va,vb;
      |       ^
answer.code:5:7: note: ‘int m’ previously declared here
    5 | int n,m,a[N],b[N],va,vb;
      |       ^
answer.code:56:9: error: redefinition of ‘int a [200005]’
   56 | int n,m,a[N],b[N],va,vb;
      |         ^
answer.code:5:9: note: ‘int a [200005]’ previously declared here
    5 | int n,m,a[N],b[N],va,vb;
      |         ^
answer.code:56:14: error: redefinition of ‘int b [200005]’
   56 | int n,m,a[N],b[N],va,vb;
      |              ^
answer.code:5:14: note: ‘int b [200005]’ previously declared here
    5 | int n,m,a[N],b[N],va,vb;
      |              ^
answer.code:56:19: error: redefinition of ‘int va’
   56 | int n,m,a[N],b[N],va,vb;
      |                   ^~
answer.code:5:19: note: ‘int va’ previously declared here
    5 | int n,m,a[N],b[N],va,vb;
      |                   ^~
answer.code:56:22: error: redefinition of ‘int vb’
   56 | int n,m,a[N],b[N],va,vb;
      |                      ^~
answer.code:5:22: note: ‘int vb’ previously declared here
    5 | int n,m,a[N],b[N],va,vb;
      |                      ^~
answer.code:57:4: error: redefinition of ‘ll ca [200005]’
   57 | ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
      |    ^~
answer.code:6:4: note: ‘ll ca [200005]’ previously declared here
    6 | ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
      |    ^~
answer.code:57:10: error: redefinition of ‘ll cb [200005]’
   57 | ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
      |          ^~
answer.code:6:10: note: ‘ll cb [200005]’ previously declared here
    6 | ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
      |          ^~
answer.code:57:16: error: redefinition of ‘ll sa [200005]’
   57 | ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
      |                ^~
answer.code:6:16: note: ‘ll sa [200005]’ previously declared here
    6 | ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
      |                ^~
answer.code:57:22: error: redefinition of ‘ll sb [200005]’
   57 | ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
      |                      ^~
answer.code:6:22: note: ‘ll sb [200005]’ previously declared here
    6 | ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
      |                      ^~
answer.code:57:28: error: redefinition of ‘ll pa [200005]’
   57 | ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
      |                            ^~
answer.code:6:28: note: ‘ll pa [200005]’ previously declared here
    6 | ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
      |                            ^~
answer.code:57:34: error: redefinition of ‘ll pb [200005]’
   57 | ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
      |                                  ^~
answer.code:6:34: note: ‘ll pb [200005]’ previously declared here
    6 | ll ca[N],cb[N],sa[N],sb[N],pa[N],pb[N];
      |                                  ^~
answer.code:58:5: error: redefinition of ‘int calc(ll, ll, ll, ll)’
   58 | int calc(ll x,ll y,ll lim,ll op){
      |     ^~~~
answer.code:7:5: note: ‘int calc(ll, ll, ll, ll)’ previously defined here
    7 | int calc(ll x,ll y,ll lim,ll op){
      |     ^~~~
answer.code:67:6: error: redefinition of ‘bool check(int)’
   67 | bool check(int lim){
      |      ^~~~~
answer.code:16:6: note: ‘bool check(int)’ previously defined here
   16 | bool check(int lim){
      |      ^~~~~
answer.code:88:5: error: redefinition of ‘int main()’
   88 | int main(){
      |     ^~~~
answer.code:37:5: note: ‘int main()’ previously defined here
   37 | int main(){
      |     ^~~~
answer.code: In function ‘int main()’:
answer.code:40:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
answer.code:41:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |     for(int i=1;i<=n;i++)scanf("%d",a+i);va=a[1];
      |                          ~~~~~^~~~~~~~~~
answer.code:42:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |     for(int i=1;i<=m;i++)scanf("%d",b+i);vb=b[1];
      |                          ~~~~~^~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:91:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unuse...