1 solutions

  • 0
    @ 2026-11-11 10:52:35
    #include<bits/stdc++.h>
    using namespace std;
    const int N=5e5+10,M=3e5+10;
    int a[N];
    bool st[M];
    int cnt[M];
    int main()
    {
    	int n,m;
    	cin>>n>>m;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>a[i];
    	}
    	
    	for(int i=1;i<=n;i++)
    	{
    		stack<int> stk;
    		memset(st,0,sizeof st);
    		for(int j=i;j<=n;j++)
    		{
    			while(st[a[j]])
    			{
    				st[stk.top()]=0;
    				stk.pop();
    			}
    			stk.push(a[j]);
    			st[a[j]]=1;
    		}
    		for(int j=1;j<=m;j++)
    		{
    			if(st[j])
    			{
    				cnt[j]++;
    			}
    		}
    	}
    	for(int i=1;i<=m;i++)
    	{
    		cout<<cnt[i]<<" ";
    	}
    }
    
    • 1

    Information

    ID
    3617
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    2
    Accepted
    0
    Uploaded By