1 solutions

  • 0
    @ 2024-12-10 22:16:31

    C++ :

    #include<iostream>
    #include<cstring>
    #include<string>
    using namespace std;
    int n,k,p,sd,xf,ans=0;
    int fzs[101],zs[101];
    bool tb;
    int main()
    {
        cin>>n>>k>>p;
        for(int i=1;i<=n;i++)
        {
          cin>>sd>>xf;
          fzs[sd]++;
          if(xf<=p)
          {
            memcpy(zs,fzs,sizeof(fzs));
            ans+=zs[sd]-1;
          }
          else
            ans+=zs[sd];
        }
        cout<<ans<<endl;
        return 0;
    }
    

    Pascal :

    var
      i,m,ans,t,n,k,p:longint;
      lc,w,c:array[1..200000]of longint;
      l,r:array[0..50]of longint;
    procedure cal(x:longint);
    var
      j:longint;
    begin
      for j:=0 to k-1 do
      inc(ans,l[j]*r[j]);
      inc(ans,l[c[lc[x]]]-1);
    end;
    begin
      readln(n,k,p);
      t:=0;
      ans:=0;
      for i:=1 to n do
        begin
          readln(c[i],w[i]);
          if w[i]<=p
            then
              begin
                inc(t);
                lc[t]:=i;
              end;
        end;
      for i:=1 to n do
        begin
          if i<=lc[1]
            then
              inc(l[c[i]])
            else
              inc(r[c[i]]);
        end;
      cal(1);
      for i:=2 to t do
        begin
          fillchar(l,sizeof(l),0);
          for m:=lc[i-1]+1 to lc[i] do
            begin
              inc(l[c[m]]);
              dec(r[c[m]]);
            end;
          cal(i);
        end;
      writeln(ans);
    end.
    
    • 1

    Information

    ID
    536
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By