离谱优化
查看原帖
离谱优化
1049051
JiuZhE66666楼主2024/4/16 12:46

这是我一开始的代码

#include<bits/stdc++.h>
using namespace std;
map<int,vector<int> > mp;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        mp.clear();
        int n,x;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>x;
            mp[x].emplace_back(i);
        }

        int q;
        cin>>q;
        while(q--)
        {
            int l,r;
            cin>>l>>r>>x;
            int len=upper_bound(mp[x].begin(),mp[x].end(),r)-lower_bound(mp[x].begin(),mp[x].end(),l);
            cout<<len<<endl;
        }
    }
    return 0;
}

但是TLE,40pts

然后我把

cout<<len<<endl;

换成了

cout<<len<<"\n";

然后就AC了

2024/4/16 12:46
加载中...