Блог пользователя Naithani

Автор Naithani, история, 5 лет назад, По-английски

I have used an efficient way to insert into the set from the rear end and delete it from another(like sliding window). DP array will store the addresses of the inserted node, when we need to delete that node, we don't need to apply to find() function. Just use that address then the node is deleted... I hope this will be helpful for somebody...

#include<bits/stdc++.h>
#define endl '\n'
#define F(i,a,b) for(int i=(int)a;i<=(int)b;i++)
using namespace std;

void solve()
{
    int t;
    cin >> t;

    while(t--)
    {
        string s;
        cin >> s;

        multiset <char> store;

        for(auto i: s) store.insert(i);

        string hash;
        cin >> hash;

        multiset <char> match;
        multiset<char>::iterator dp[hash.size()];

        bool possible = false;

        F(i,0, hash.size() -1)
        {
            dp[i] = match.insert(hash[i]);
             

            if(match.size()==store.size())
            {
                if(match == store)
                {
                    possible = true;
                    break;
                }
                else
                {
                    match.erase(dp[i-store.size()+1]);
                }

            }
        }

        if(possible) cout << "YES";
        else cout << "NO";

        cout << endl;

    }

}


int main(){
    
    solve();

    return 0;
}


  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится