Submission #836889

# Submission time Handle Problem Language Result Execution time Memory
836889 2023-08-24T16:53:59 Z borisAngelov Examination (JOI19_examination) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int maxn = 600005;
const int max_number = 600000;
 
int n, q;
 
struct element
{
    int x;
    int y;
    int z;
 
    bool is_query;
    int query_idx;
};
 
element a[maxn];

inline friend bool <(element fr, element sc)
{
	return (fr.x > sc.x || (fr.x == sc.x && fr.is_query == false));
}
 
void compress()
{
    vector<int> to_sort;
    unordered_map<int, int> compressed;
    int curr_value = 0;
 
    for (int i = 1; i <= n + q; ++i)
    {
        to_sort.push_back(a[i].x);
        to_sort.push_back(a[i].y);
        to_sort.push_back(a[i].z);
    }
 
    sort(to_sort.begin(), to_sort.end());
 
    for (int i = 0; i < to_sort.size(); ++i)
    {
        if (i == 0 || to_sort[i] != to_sort[i - 1])
        {
            compressed[to_sort[i]] = ++curr_value;
        }
    }
 
 
    for (int i = 1; i <= n + q; ++i)
    {
        a[i].x = compressed[a[i].x];
        a[i].y = compressed[a[i].y];
        a[i].z = compressed[a[i].z];
    }
}
 
int answers[maxn];
 
struct fenwick_tree
{
    int tree[maxn];
 
    void update(int pos, int delta)
    {
        for (int i = pos; i <= max_number; i += (i & (-i)))
        {
            tree[i] += delta;
        }
    }
 
    int query(int pos)
    {
        int result = 0;
 
        for (int i = pos; i >= 1; i -= (i & (-i)))
        {
            result += tree[i];
        }
 
        return result;
    }
};
 
fenwick_tree bit;
 
void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
 
int main()
{
    fastIO();
 
    cin >> n >> q;
 
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i].x >> a[i].y;
        a[i].z = a[i].x + a[i].y;
    }
 
    for (int i = 1; i <= q; ++i)
    {
        cin >> a[i + n].x >> a[i + n].y >> a[i + n].z;
        a[i + n].is_query = true;
        a[i + n].query_idx = i;
    }
 
    compress();
 
    sort(a + 1, a + n + q + 1, cmp);
 
    for (int i = 1; i <= n + q; ++i)
    {
        if (a[i].is_query == false)
        {
            bit.update(a[i].y, +1);
        }
        else
        {
            answers[a[i].query_idx] = (bit.query(max_number) - bit.query(a[i].y - 1));
        }
    }
 
    for (int i = 1; i <= q; ++i)
    {
        cout << answers[i] << "\n";
    }
 
    return 0;
}
 
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 0
10 10 0
60 60 0
0 100 0
*/

Compilation message

examination.cpp:22:8: error: 'friend' used outside of class
   22 | inline friend bool <(element fr, element sc)
      |        ^~~~~~
      |        ------
examination.cpp:22:15: error: 'bool' is not a template
   22 | inline friend bool <(element fr, element sc)
      |               ^~~~
examination.cpp:22:30: error: expected primary-expression before 'fr'
   22 | inline friend bool <(element fr, element sc)
      |                              ^~
examination.cpp:22:29: error: expected ')' before 'fr'
   22 | inline friend bool <(element fr, element sc)
      |                     ~       ^~~
      |                             )
examination.cpp:27:1: error: expected '>' before 'void'
   27 | void compress()
      | ^~~~
examination.cpp:28:1: error: expected unqualified-id before '{' token
   28 | {
      | ^
examination.cpp: In function 'int main()':
examination.cpp:114:5: error: 'compress' was not declared in this scope
  114 |     compress();
      |     ^~~~~~~~
examination.cpp:116:32: error: 'cmp' was not declared in this scope; did you mean 'bcmp'?
  116 |     sort(a + 1, a + n + q + 1, cmp);
      |                                ^~~
      |                                bcmp