QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#485917#8749. 贸易LYT0122WA 12ms58760kbC++141.7kb2024-07-21 12:26:212024-07-21 12:26:21

Judging History

This is the latest submission verdict.

  • [2024-07-21 12:26:21]
  • Judged
  • Verdict: WA
  • Time: 12ms
  • Memory: 58760kb
  • [2024-07-21 12:26:21]
  • Submitted

answer

#include <iostream>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
const int N=1e6+9,INF=1e9;
const double eps=1e-7;
typedef pair <int,int> PII;
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0' || c>'9') {if(c=='-') f=-1;c=getchar();}
    while(c>='0' && c<='9') {x=x*10+c-48,c=getchar();}
    return x*f;
}
inline ll readll()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0' || c>'9') {if(c=='-') f=-1;c=getchar();}
    while(c>='0' && c<='9') {x=x*10+c-48,c=getchar();}
    return x*f;
}
int n,q,a[N],c[N],l[N],tr[N],ans[N];
vector <int> st[N];
vector <PII> qu[N];
int lowbit(int x)
{
    return x&-x;
}
void add(int x,int v)
{
    while(x<=n) tr[x]+=v,x+=lowbit(x);
}
int query(int x)
{
    int ans=0;
    while(x!=0) ans+=tr[x],x-=lowbit(x);
    return ans;
}
int main()
{
    n=read(),q=read();
    for(int i=1;i<=n;i++) a[i]=read();
    for(int i=1;i<=n;i++) c[i]=read();
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0) st[c[i]].push_back(i);
        else if(st[c[i]].empty()==false) l[i]=st[c[i]].back(),st[c[i]].pop_back();
    }
    for(int i=1;i<=q;i++)
    {
        int l=read(),r=read();
        qu[r].push_back({l,i});
    }
    for(int i=1;i<=n;i++)
    {
        if(l[i]!=0) add(l[i],1);
        for(int j=0;j<qu[i].size();j++)
        {
            int l=qu[i][j].first,id=qu[i][j].second;
            ans[id]=query(n)-query(l-1);
        }
    }
    for(int i=1;i<=q;i++) cout<<ans[i]<<" ";
    cerr<<endl<<1e3*clock()/CLOCKS_PER_SEC<<"ms";
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 12ms
memory: 58760kb

input:

10 5
1 1 0 0 0 0 0 1 1 1
1 1 1 1 1 1 1 1 1 1
4 6
2 4
2 6
7 10
4 7

output:

0 0 0 1 0 

result:

wrong answer 1st lines differ - expected: '0', found: '0 0 0 1 0 '