QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#105430#6192. Interval ProblemLiberty12619Compile Error//C++201.4kb2023-05-14 02:11:262023-05-14 02:11:27

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-14 02:11:27]
  • 评测
  • [2023-05-14 02:11:26]
  • 提交

answer

//https://qoj.ac/contest/1195/problem/6192
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int,int>PII;
void solve()
{
    int n;
    cin>>n;
    vector<PII>reg(n+5);
    vector<int>ans(n+5,0);
    for(int i=1;i<=n;i++)   scanf("%lld%lld",&reg[i].x,&reg[i].y);
    for(int i=1;i<=n;i++)   ans[i]=n-1;
    auto work = [&]()
    {
        vector<int>p(2*n+5,INF),sum(2*n+5,0),f(2*n+5,0),g(2*n+5,0),h(2*n+5,0);
        
        for(int i=1;i<=n;i++)   sum[reg[i].y]++,p[reg[i].y]=reg[i].x;
        
        for(int i=1;i<=2*n;i++) sum[i]+=sum[i-1];
        for(int i=2*n;i>=1;i--) p[i]=min(p[i],p[i+1]);
        for(int i=1;i<=2*n;i++)
        {
            if(p[i]>=i)
            {
                g[i]=i;
                f[i]=h[i]=0;
            }
            else
            {
                g[i]=g[p[i]];
                f[i]=f[p[i]]+sum[i-1];
                h[i]=h[p[i]]+1;
            }
        }
        
        for(int i=1;i<=n;i++)
        {
            int x = reg[i].x,y=g[reg[i].x];
            ans[i]+=f[x]-sum[y-1]*(h[x]+1);
        }
        
    };
    work();
    for(int i=1;i<=n;i++)
    {
        reg[i].x=2*n+1-reg[i].x,reg[i].y=2*n+1-reg[i].y;
        swap(reg[i].x,reg[i].y);
    }
    work();
    for(int i=1;i<=n;i++)   printf("%lld\n",ans[i]);
}
signed main()
{
	int T=1;
	while(T--)
	{
		solve();
	}
	return 0;
}

Details

answer.code: In lambda function:
answer.code:18:28: error: ‘INF’ was not declared in this scope
   18 |         vector<int>p(2*n+5,INF),sum(2*n+5,0),f(2*n+5,0),g(2*n+5,0),h(2*n+5,0);
      |                            ^~~
answer.code: In function ‘void solve()’:
answer.code:14:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |     for(int i=1;i<=n;i++)   scanf("%lld%lld",&reg[i].x,&reg[i].y);
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~