Why is this code TLEing on OJ but is working fine on my local machine

Правка en3, от priy1712, 2024-02-23 09:25:04
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#define ci(n) cin>>n
#define co(n) cout<<n
#define nl '\n'
#define r0 return 0
#define LLMAX LLONG_MAX
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define printstr(s) for(int i=0;i<(int)s.size();i++) { cout<<s[i];}
typedef std::pair<int, int> pp;
typedef long long ll;
typedef std::vector<ll> vl;
typedef std::vector<std::pair<int, int>> vp;
typedef std::vector<int> vi;
typedef std::unordered_map<int, int> unmap;
typedef std::unordered_set<int> unset;
typedef std::unordered_set<char> unsetc;
using namespace std;


const int max_size = 100005;
vector<bitset<1005>> b(max_size);//matrix of bitsets.
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // unordered_map<ll, ll> mp;
    // mp.reserve(1024);
    // mp.max_load_factor(0.25);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll n, q;
    ci(n); ci(q);
    for (int i = 1; i <= n; ++i)
    {
        ll k;
        ci(k);
        for (int j = 0; j < k; ++j)
        {
            ll item; ci(item);
            b[i].set(item);//in stock.
        }
    }
    while (q--)
    {
        int curquery;
        ci(curquery);
        // co(curquery); co(nl);
        if (curquery == 1) //have to replace items in a shop
        {
            ll shop; ci(shop);
            ll k;
            ci(k);
            // const int curk = k;
            bitset < 1005> items;
            items.reset();
            for (int i = 0; i < k; ++i)
            {
                int x; ci(x);
                items[x] = 1;
                b[shop] &= items;//the common ones will stay 1.
                //others will become 0.
            }
        }
        else
        {
            ll l, r; ci(l); ci(r);
            ll k; ci(k);
            bitset < 1005> items;
            items.reset();
            for (int i = 0; i < k ; ++i)
            {
                int x; ci(x);
                items[x] = 1;//items he is willing to sell. the shopkeepers
                //will buy only if their intersection with the chef is 0.
                //that is , no common items
            }
            bitset<1005> cur;
            cur.reset();
            ll res = 0;
            for (int i = l; i <= r; ++i)
            {
                cur = b[i];
                cur &= items;
                if (cur.count() == 0)
                {
                    res++;
                }
                cur.reset();
            }
            co(res); co(nl);
        }
    }
    r0;
}

The above code compiles fine and gives the correct output too on my local machine but its TLEIng when I submit it to the OJ, could anyone help me out? thanks. The problem statement : https://www.codechef.com/problems/T30?tab=statement

UPD: it works fine on codeforces custom invocation too.

Теги need help

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский priy1712 2024-02-23 09:25:04 61
en2 Английский priy1712 2024-02-23 09:12:54 997
en1 Английский priy1712 2024-02-23 09:12:26 4073 Initial revision (published)