1 条题解

  • 0
    @ 2021-6-15 1:40:16

    C++ :

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define rep(i,n) for(int i=1;i<=n;i++)
    using namespace std;
    
    const int N=200010;
    
    int n,k,p;
    int col[N],pri[N],s[N][55];
    long long ans;
    
    int fa[N];
    int find(int x) {
    	if(x>n||pri[x]<=p)return x;
    	if(!fa[x])fa[x]=x+1;
    	return fa[x]=find(fa[x]);
    }
    
    int main() {
    	
    	scanf("%d%d%d",&n,&k,&p);
    	rep(i,n) {
    		scanf("%d%d",&col[i],&pri[i]);
    		for(int j=0;j<=50;j++)s[i][j]=s[i-1][j];
    		s[i][col[i]]++;
    	}
    	
    	rep(i,n) {
    		int j=find(i);
    		if(j>n)continue;
    		if(j==i)ans+=s[n][col[i]]-s[j][col[i]];
    		else ans+=s[n][col[i]]-s[j-1][col[i]];
    	}
    	
    	printf("%lld\n",ans);
    	
    	return 0;
    }
    

    Pascal :

    var  
      a,b:array[0..50] of longint;  
      i,j,k,m,n,s,t:longint;  
    begin  
      readln(n,k,m);  
      j:=0;
    	fillchar(a,sizeof(a),0);
      for i:=1 to n do  
      begin  
        readln(s,t);  
        a[s]:=a[s]+1;  
        if t<=m then  
        begin  
          b:=a;  
          j:=j+b[s]-1;  
        end else j:=j+b[s];  
      end;  
      write(j);  
    end.
    
    • 1

    信息

    ID
    289
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者