Submission #262207

# Submission time Handle Problem Language Result Execution time Memory
262207 2020-08-12T13:29:05 Z sckmd Examination (JOI19_examination) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
#define MAXN 100005
int a[MAXN];
int b[MAXN];
int sol[MAXN];
int n;
int BLOCK;
vector <int> ids;
vector <int> idsz;

bool cmp(que a,que b)
{
  return a.x > b.x;
}
bool cmpp(int x,int y)
{
  return a[x]>a[y];
}
bool cmppp(int x,int y)
{
  return b[x]<b[y];
}
vector <int> strk[400];
int pozniz[MAXN];
bool active[MAXN];

void update(int origid)
{
  int pozuniz = pozniz[origid];
  int bl = pozuniz/BLOCK;
  strk[bl].push_back(a[origid]+b[origid]);
  sort(strk[bl].begin(),strk[bl].end());
  active[origid]=true;
}

int lowb(int y)
{
  int lo = 0,hi=n-1,r=n;
  int mid;
  while(lo <= hi)
  {
    mid=lo+hi>>1;
    if(b[idsz[mid]]>=y)r=mid,hi=mid-1;
    else lo=mid+1;
  }
  return r;
}

int query(int y,int z)
{
  int ans = 0;
  int bl = 0;
  int startpos = lowb(y);
  while(startpos%BLOCK != 0 && startpos < n)
  {
    if(!active[idsz[startpos]]){startpos++;continue;}
    if(a[idsz[startpos]]+b[idsz[startpos]] >= z)ans++;
    startpos++;
  }
  if(startpos % BLOCK != 0 || startpos == n)return ans;
  for(int bl = startpos/BLOCK; bl <= (n-1)/BLOCK; bl++)
  {
    auto it = lower_bound(strk[bl].begin(),strk[bl].end(),z);
    int pos = it-strk[bl].begin();
    ans += max(0,n-1-pos+1);
  }
  return ans;
}

int main()
{
  ios_base::sync_with_stdio(false);
  int q;
  cin >> n >> q;
  BLOCK = sqrt(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i] >> b[i];
    ids.push_back(i);
    idsz.push_back(i);
  }
  for(int i = 0; i < q; i++)
  {
    cin >> qq[i].x >> qq[i].y >> qq[i].z;
    qq[i].id=i;
  }
  sort(qq,qq+q,cmp);
  sort(ids.begin(),ids.end(),cmpp);
  sort(idsz.begin(),idsz.end(),cmppp);
  for(int i = 0; i < idsz.size(); i++)pozniz[idsz[i]]=i;
  int now = 0;
  for(int i = 0; i < q; i++)
  {
    while(q[i].x <= a[ids[now]] && now < n)update(now),now++;
    ans[q[i].id]=query(q[i].y,q[i].z);
  }
  for(int i = 0; i < q; i++)cout << ans[i] << "\n";
  return 0;
}
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100
*/

Compilation message

examination.cpp:13:10: error: 'que' was not declared in this scope
   13 | bool cmp(que a,que b)
      |          ^~~
examination.cpp:13:16: error: 'que' was not declared in this scope
   13 | bool cmp(que a,que b)
      |                ^~~
examination.cpp:13:21: error: expression list treated as compound expression in initializer [-fpermissive]
   13 | bool cmp(que a,que b)
      |                     ^
examination.cpp: In function 'int lowb(int)':
examination.cpp:44:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |     mid=lo+hi>>1;
      |         ~~^~~
examination.cpp: In function 'int query(int, int)':
examination.cpp:54:7: warning: unused variable 'bl' [-Wunused-variable]
   54 |   int bl = 0;
      |       ^~
examination.cpp: In function 'int main()':
examination.cpp:86:12: error: 'qq' was not declared in this scope; did you mean 'q'?
   86 |     cin >> qq[i].x >> qq[i].y >> qq[i].z;
      |            ^~
      |            q
examination.cpp:89:8: error: 'qq' was not declared in this scope; did you mean 'q'?
   89 |   sort(qq,qq+q,cmp);
      |        ^~
      |        q
examination.cpp:92:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |   for(int i = 0; i < idsz.size(); i++)pozniz[idsz[i]]=i;
      |                  ~~^~~~~~~~~~~~~
examination.cpp:96:14: error: invalid types 'int[int]' for array subscript
   96 |     while(q[i].x <= a[ids[now]] && now < n)update(now),now++;
      |              ^
examination.cpp:97:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   97 |     ans[q[i].id]=query(q[i].y,q[i].z);
      |     ^~~
      |     abs
examination.cpp:97:12: error: invalid types 'int[int]' for array subscript
   97 |     ans[q[i].id]=query(q[i].y,q[i].z);
      |            ^
examination.cpp:97:27: error: invalid types 'int[int]' for array subscript
   97 |     ans[q[i].id]=query(q[i].y,q[i].z);
      |                           ^
examination.cpp:97:34: error: invalid types 'int[int]' for array subscript
   97 |     ans[q[i].id]=query(q[i].y,q[i].z);
      |                                  ^
examination.cpp:99:37: error: 'ans' was not declared in this scope; did you mean 'abs'?
   99 |   for(int i = 0; i < q; i++)cout << ans[i] << "\n";
      |                                     ^~~
      |                                     abs