Submission #255828

# Submission time Handle Problem Language Result Execution time Memory
255828 2020-08-01T22:48:15 Z uacoder123 Examination (JOI19_examination) C++14
22 / 100
3000 ms 286224 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
 
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
typedef tree<
iii,
null_type,
less<iii>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

ordered_set segt[8*100000+1];
lli n,q,co=0;
void up(lli node,lli l,lli r,lli in,lli v)
{
  segt[node].insert(mp(v,mp(q+1,co)));
  co++;
  lli m=(l+r)/2;
  if(l!=r)
  {
    if(in<=m)
      up(2*node+1,l,m,in,v);
    else
      up(2*node+2,m+1,r,in,v);
  }
}
lli query(lli node,lli l,lli r,lli s,lli e,lli v)
{
  if(r<s||l>e)
    return(0);
  if(l>=s&&r<=e)
    return segt[node].size()-segt[node].order_of_key(mp(v,mp(0,0)));
  lli m=(l+r)/2;
  lli q1=query(2*node+1,l,m,s,e,v),q2=query(2*node+2,m+1,r,s,e,v);
  return(q1+q2);
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin>>n>>q;
  multiset<pair<ii,ii>> se;
  set<lli> v;
  unordered_map<lli,lli> m;
  ii s[n];
  pair<ii,lli> qu[q];
  for(lli i=0;i<n;++i)
  {
    cin>>s[i].F>>s[i].S;
    v.insert(s[i].F);
    v.insert(s[i].S);
    v.insert(s[i].F+s[i].S);
  }
  for(lli i=0;i<q;++i)
  {
    cin>>qu[i].F.F>>qu[i].F.S>>qu[i].S;
    v.insert(qu[i].F.F);
    v.insert(qu[i].F.S);
    v.insert(qu[i].S); 
  }
  auto it=v.begin();
  lli c=0,c1=0;
  while(it!=v.end())
  {
    m[(*it)]=c;
    c++;
    it++;
  }
  for(lli i=0;i<n;++i)
  {
    lli su=s[i].F+s[i].S;
    s[i].F=m[s[i].F];
    s[i].S=m[s[i].S];
    se.insert(mp(mp(s[i].F,q+11),mp(s[i].S,m[su])));
  }
  for(lli i=0;i<q;++i)
  {
    qu[i].F.S=m[qu[i].F.S];
    qu[i].F.F=m[qu[i].F.F];
    qu[i].S=m[qu[i].S];
    se.insert(mp(mp(qu[i].F.F,i),mp(qu[i].F.S,qu[i].S)));
  }
  auto it1=se.begin();
  vector<ii> st[c];
  vector<iii> que[c];
  while(it1!=se.end())
  {
    lli in=(*it1).S.S;
    if((*it1).F.S!=q+11)
      que[in].pb(mp((*it1).F.S,mp(c1,(*it1).S.F)));
    else
      st[in].pb(mp(c1,(*it1).S.F));
    it1++;
    c1++;
  }
  lli ans[q]={};
  for(lli i=c-1;i>=0;--i)
  {
    for(lli j=0;j<st[i].size();++j)
      up(0,0,c1-1,st[i][j].F,st[i][j].S);
    for(lli j=0;j<que[i].size();++j)
      ans[que[i][j].F]=query(0,0,c1-1,que[i][j].S.F,c1-1,que[i][j].S.S);
  }
  for(lli i=0;i<q;++i)
    cout<<ans[i]<<endl;
  return(0);
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:114:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(lli j=0;j<st[i].size();++j)
                 ~^~~~~~~~~~~~~
examination.cpp:116:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(lli j=0;j<que[i].size();++j)
                 ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 70 ms 88056 KB Output is correct
2 Correct 77 ms 88056 KB Output is correct
3 Correct 74 ms 88056 KB Output is correct
4 Correct 83 ms 88056 KB Output is correct
5 Correct 73 ms 88056 KB Output is correct
6 Correct 71 ms 88068 KB Output is correct
7 Correct 111 ms 94584 KB Output is correct
8 Correct 113 ms 94584 KB Output is correct
9 Correct 112 ms 94584 KB Output is correct
10 Correct 107 ms 93692 KB Output is correct
11 Correct 105 ms 93736 KB Output is correct
12 Correct 94 ms 92024 KB Output is correct
13 Correct 103 ms 94268 KB Output is correct
14 Correct 113 ms 94200 KB Output is correct
15 Correct 105 ms 94184 KB Output is correct
16 Correct 97 ms 92920 KB Output is correct
17 Correct 128 ms 93304 KB Output is correct
18 Correct 89 ms 91968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2940 ms 280564 KB Output is correct
2 Correct 2535 ms 281624 KB Output is correct
3 Correct 2701 ms 281552 KB Output is correct
4 Correct 1707 ms 274724 KB Output is correct
5 Correct 1693 ms 274828 KB Output is correct
6 Correct 1152 ms 260580 KB Output is correct
7 Correct 2453 ms 281592 KB Output is correct
8 Correct 2811 ms 281248 KB Output is correct
9 Correct 2564 ms 281036 KB Output is correct
10 Correct 1246 ms 273660 KB Output is correct
11 Correct 1382 ms 273660 KB Output is correct
12 Correct 1094 ms 260056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2940 ms 280564 KB Output is correct
2 Correct 2535 ms 281624 KB Output is correct
3 Correct 2701 ms 281552 KB Output is correct
4 Correct 1707 ms 274724 KB Output is correct
5 Correct 1693 ms 274828 KB Output is correct
6 Correct 1152 ms 260580 KB Output is correct
7 Correct 2453 ms 281592 KB Output is correct
8 Correct 2811 ms 281248 KB Output is correct
9 Correct 2564 ms 281036 KB Output is correct
10 Correct 1246 ms 273660 KB Output is correct
11 Correct 1382 ms 273660 KB Output is correct
12 Correct 1094 ms 260056 KB Output is correct
13 Execution timed out 3002 ms 286224 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 70 ms 88056 KB Output is correct
2 Correct 77 ms 88056 KB Output is correct
3 Correct 74 ms 88056 KB Output is correct
4 Correct 83 ms 88056 KB Output is correct
5 Correct 73 ms 88056 KB Output is correct
6 Correct 71 ms 88068 KB Output is correct
7 Correct 111 ms 94584 KB Output is correct
8 Correct 113 ms 94584 KB Output is correct
9 Correct 112 ms 94584 KB Output is correct
10 Correct 107 ms 93692 KB Output is correct
11 Correct 105 ms 93736 KB Output is correct
12 Correct 94 ms 92024 KB Output is correct
13 Correct 103 ms 94268 KB Output is correct
14 Correct 113 ms 94200 KB Output is correct
15 Correct 105 ms 94184 KB Output is correct
16 Correct 97 ms 92920 KB Output is correct
17 Correct 128 ms 93304 KB Output is correct
18 Correct 89 ms 91968 KB Output is correct
19 Correct 2940 ms 280564 KB Output is correct
20 Correct 2535 ms 281624 KB Output is correct
21 Correct 2701 ms 281552 KB Output is correct
22 Correct 1707 ms 274724 KB Output is correct
23 Correct 1693 ms 274828 KB Output is correct
24 Correct 1152 ms 260580 KB Output is correct
25 Correct 2453 ms 281592 KB Output is correct
26 Correct 2811 ms 281248 KB Output is correct
27 Correct 2564 ms 281036 KB Output is correct
28 Correct 1246 ms 273660 KB Output is correct
29 Correct 1382 ms 273660 KB Output is correct
30 Correct 1094 ms 260056 KB Output is correct
31 Execution timed out 3002 ms 286224 KB Time limit exceeded
32 Halted 0 ms 0 KB -