Submission #572819

# Submission time Handle Problem Language Result Execution time Memory
572819 2022-06-05T10:39:54 Z Huy Examination (JOI19_examination) C++17
0 / 100
311 ms 70340 KB
#include<bits/stdc++.h>
//#define int long long
#define pii pair<ll,ll>
#define fi first
#define se second

using namespace std;
using ll = long long;
using ldb = long double;
const int N = (int)1e8;
const int maxN = (int)2e5 + 5;
const int mod = 1e9 + 7;
const ll infty = 1e18;

void InputFile()
{
    //freopen("scrivener.inp","r",stdin);
    //freopen("scrivener.out","w",stdout);
    freopen("test.out","r",stdin);
}

void FastInput()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int n,q;
int s[maxN],t[maxN];
int id[maxN];
vector<int> vec;

bool FA(int i,int j)
{
    return s[i] < s[j];
}

vector<int> ST[2][4*maxN];

vector<int> Merge(vector<int> a,vector<int> b)
{
    vector<int> res;
    int pta = 0;
    int ptb = 0;
    while(pta < a.size() || ptb < b.size())
    {
        if(pta == a.size())
        {
            res.push_back(b[ptb]);
            ptb++;
        }
        else if(ptb == b.size())
        {
            res.push_back(a[pta]);
            pta++;
        }
        else if(a[pta] <= b[ptb])
        {
            res.push_back(a[pta]);
            pta++;
        }
        else
        {
            res.push_back(b[ptb]);
            ptb++;
        }
    }
    return res;
}

void Build(int id,int l,int r)
{
    if(l == r)
    {
        ST[0][id] = {t[l]};
        ST[1][id] = {s[l] + t[l]};
        return;
    }
    int mid = (l + r) / 2;
    Build(id * 2,l,mid);
    Build(id * 2 + 1,mid + 1,r);
    ST[0][id] = Merge(ST[0][id*2],ST[0][id*2+1]);
    ST[1][id] = Merge(ST[1][id*2],ST[1][id*2+1]);
}

int Get(int id,int l,int r,int u,int v,int cval,int t)
{
    if(v < l || u > r) return 0;
    if(u <= l && r <= v)
    {
        int val = ST[t][id].size() - (lower_bound(ST[t][id].begin(),ST[t][id].end(),cval) - ST[t][id].begin());
        return val;
    }
    int mid = (l + r) / 2;
    return Get(id * 2,l,mid,u,v,cval,t) + Get(id * 2 + 1,mid + 1,r,u,v,cval,t);
}

void Read()
{
    cin >> n >> q;
    for(int i = 1;i <= n;i++)
    {
        cin >> s[i] >> t[i];
        id[i] = i;
    }
    sort(id + 1,id + n + 1,FA);
    for(int i = 1;i <= n;i++) vec.push_back(s[id[i]]);
    for(int i = 1;i <= n;i++) s[i] = vec[i-1];
    vec.clear();
    for(int i = 1;i <= n;i++) vec.push_back(t[id[i]]);
    for(int i = 1;i <= n;i++) t[i] = vec[i-1];
    Build(1,1,n);
    for(int i = 1;i <= n;i++)
    {
        cout << s[i] <<' '<< t[i] <<'\n';
    }
    while(q--)
    {
        int A,B,C;
        cin >> A >> B >> C;
        int L = lower_bound(s + 1,s + n + 1,A) - s;
        int R = upper_bound(s + 1,s + n + 1,C - B) - s;
        int res = 0;
        if(L <= R - 1)
        {
            res += Get(1,1,n,L,R-1,C,1);
        }
        R = max(R,L);
        res += (Get(1,1,n,R,n,B,0));
        cout << res <<'\n';
    }
}

void Solve()
{

}

void Debug()
{
    //Main_sub();
    //Naive();
}


int32_t main()
{
    FastInput();
    //InputFile();
    //int sub_type;
    //cin >> sub_type;
    //Sieve();
    int test;
    //cin >> test;
    test = 1;
    while(test--)
        //for(int prc = 1; prc <= test; prc++)
    {
        Read();
        Solve();
        //Debug();
    }
}

/*
4 1
1 1 1 1
1 2
2 3
3 4
*/

Compilation message

examination.cpp: In function 'std::vector<int> Merge(std::vector<int>, std::vector<int>)':
examination.cpp:45:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     while(pta < a.size() || ptb < b.size())
      |           ~~~~^~~~~~~~~~
examination.cpp:45:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     while(pta < a.size() || ptb < b.size())
      |                             ~~~~^~~~~~~~~~
examination.cpp:47:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         if(pta == a.size())
      |            ~~~~^~~~~~~~~~~
examination.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         else if(ptb == b.size())
      |                 ~~~~^~~~~~~~~~~
examination.cpp: In function 'void InputFile()':
examination.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen("test.out","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 37844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 311 ms 70340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 311 ms 70340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 37844 KB Output isn't correct
2 Halted 0 ms 0 KB -