#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define sqrt sqrtl
using namespace std;
const long long oo = 1000000000000000000;
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
int n, m, a[ 100001 ], b[ 100001 ], x[ 100001 ], y[ 100001 ], z[ 100001 ];
int t[ 1600001 ], tt[ 1600001 ], t1[ 1600001 ];
int an[ 100001 ];
void upd( int v, int tl, int tr, int pos ) {
if ( tl > pos || tr < pos )
return;
if ( tl == tr ) {
t[ v ] ++;
return;
}
int mid = ( tl + tr ) / 2;
upd( v + v, tl, mid, pos );
upd( v + v + 1, mid + 1, tr, pos );
t[ v ] = t[ v + v ] + t[ v + v + 1 ];
}
void updd( int v, int tl, int tr, int pos ) {
if ( tl > pos || tr < pos )
return;
if ( tl == tr ) {
tt[ v ] ++;
return;
}
int mid = ( tl + tr ) / 2;
updd( v + v, tl, mid, pos );
updd( v + v + 1, mid + 1, tr, pos );
tt[ v ] = tt[ v + v ] + tt[ v + v + 1 ];
}
void gett( int v, int tl, int tr, int l, int r ) {
if ( tl > r || tr < l )
return;
if ( tl >= l && tr <= r ) {
sum -= t[ v ];
return;
}
int mid = ( tl + tr ) / 2;
gett( v + v, tl, mid, l, r );
gett( v + v + 1, mid + 1, tr, l, r );
}
void get1( int v, int tl, int tr, int l, int r ) {
if ( tl > r || tr < l )
return;
if ( tl >= l && tr <= r ) {
sum -= tt[ v ];
return;
}
int mid = ( tl + tr ) / 2;
get1( v + v, tl, mid, l, r );
get1( v + v +1, mid +1 , tr, l, r );
}
void upd1( int v, int tl, int tr, int pos ) {
if ( tl > pos || tr < pos )
return;
if ( tl == tr ) {
t1[ v ] ++;
return;
}
int mid = ( tl + tr ) / 2;
upd1( v + v, tl, mid, pos );
upd1( v + v + 1, mid + 1, tr, pos );
t1[ v ] = t1[ v + v ] + t1[ v + v + 1 ];
}
void gett1( int v, int tl, int tr, int l, int r ) {
if ( tl > r || tr < l )
return;
if ( tl >= l && tr <= r ) {
sum += t1[ v ];
return;
}
int mid = ( tl + tr ) / 2;
gett1( v + v, tl, mid, l, r );
gett1( v + v + 1, mid + 1, tr, l, r );
}
vector <int> V;
vector <pair<int, int> > v, v1, v2, vv;
map <int, int> mp;
main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for ( int i = 1; i <= n; i ++ ) {
cin >> a[ i ] >> b[ i ];
V.push_back( a[ i ] );
V.push_back( b[ i ] );
v.push_back( { a[ i ] + b[ i ], i } );
}
for ( int i = 1; i <= m; i ++ ) {
cin >> x[ i ] >> y[ i ] >> z[ i ];
V.push_back( x[ i ] );
V.push_back( y[ i ] );
}
sort( v.begin(), v.end() );
sort( V.begin(), V.end() );
for ( auto i : V ) {
if ( !mp[ i ] )
mp[ i ] = ++num;
}
for ( int i = 1; i <= n; i ++ ) {
a[ i ] = mp[ a[ i ] ], b[ i ] = mp[ b[ i ] ];
vv.push_back( { a[ i ], i } );
}
sort( vv.begin(), vv.end() );
reverse( vv.begin(), vv.end() );
for ( int i = 1; i <= m; i ++ ) {
if ( x[ i ] + y[ i ] < z[ i ] )
v1.push_back( { z[ i ], i } );
else {
v2.push_back( { mp[ x[ i ] ], i } );
}
x[ i ] = mp[ x[ i ] ];
y[ i ] = mp[ y[ i ] ];
}
sort( v1.begin(), v1.end() );
reverse( v1.begin(), v1.end() );
reverse( v.begin(), v.end() );
for ( auto i : v1 ) {
while ( pos < v.size() && v[ pos ].first >= i.first ) {
upd( 1, 1, num, a[ v[ pos ].second ] );
updd( 1, 1, num, b[ v[ pos ].second ] );
pos ++;
}
// cout << i.second << " - ";
sum = pos;
if ( x[ i.second ] != 1 )
gett( 1, 1, num, 1, x[ i.second ] - 1 );
// cout << sum << " ";
if ( y[ i.second ] != 1 )
get1( 1, 1, num, 1, y[ i.second ] - 1 );
// cout << sum << "\n";
an[ i.second ] = sum;
}
sort( v2.begin(), v2.end() );
reverse( v2.begin(), v2.end() );
pos = 0;
for ( auto i : v2 ) {
while ( pos < v.size() && vv[ pos ].first >= i.first ) {
upd1( 1, 1, num, b[ vv[ pos ].second ] );
pos ++;
}
sum = 0;
gett1( 1, 1, num, y[ i.second ], num );
an[ i.second ] = sum;
}
for ( int i = 1; i <= m; i ++ )
cout << an[ i ] << "\n";
}
Compilation message
examination.cpp:132:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
132 | main () {
| ^~~~
examination.cpp: In function 'int main()':
examination.cpp:172:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
172 | while ( pos < v.size() && v[ pos ].first >= i.first ) {
| ~~~~^~~~~~~~~~
examination.cpp:191:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
191 | while ( pos < v.size() && vv[ pos ].first >= i.first ) {
| ~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
9 ms |
1620 KB |
Output is correct |
8 |
Correct |
10 ms |
1624 KB |
Output is correct |
9 |
Correct |
10 ms |
1696 KB |
Output is correct |
10 |
Correct |
7 ms |
1108 KB |
Output is correct |
11 |
Correct |
6 ms |
1108 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
9 ms |
1372 KB |
Output is correct |
14 |
Correct |
10 ms |
1432 KB |
Output is correct |
15 |
Correct |
9 ms |
1364 KB |
Output is correct |
16 |
Correct |
5 ms |
980 KB |
Output is correct |
17 |
Correct |
6 ms |
1108 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
288 ms |
13756 KB |
Output is correct |
2 |
Correct |
321 ms |
16280 KB |
Output is correct |
3 |
Correct |
288 ms |
16304 KB |
Output is correct |
4 |
Correct |
211 ms |
14160 KB |
Output is correct |
5 |
Correct |
247 ms |
14984 KB |
Output is correct |
6 |
Correct |
87 ms |
9180 KB |
Output is correct |
7 |
Correct |
288 ms |
16032 KB |
Output is correct |
8 |
Correct |
272 ms |
16056 KB |
Output is correct |
9 |
Correct |
255 ms |
15712 KB |
Output is correct |
10 |
Correct |
223 ms |
14836 KB |
Output is correct |
11 |
Correct |
195 ms |
13840 KB |
Output is correct |
12 |
Correct |
60 ms |
8808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
288 ms |
13756 KB |
Output is correct |
2 |
Correct |
321 ms |
16280 KB |
Output is correct |
3 |
Correct |
288 ms |
16304 KB |
Output is correct |
4 |
Correct |
211 ms |
14160 KB |
Output is correct |
5 |
Correct |
247 ms |
14984 KB |
Output is correct |
6 |
Correct |
87 ms |
9180 KB |
Output is correct |
7 |
Correct |
288 ms |
16032 KB |
Output is correct |
8 |
Correct |
272 ms |
16056 KB |
Output is correct |
9 |
Correct |
255 ms |
15712 KB |
Output is correct |
10 |
Correct |
223 ms |
14836 KB |
Output is correct |
11 |
Correct |
195 ms |
13840 KB |
Output is correct |
12 |
Correct |
60 ms |
8808 KB |
Output is correct |
13 |
Correct |
392 ms |
18384 KB |
Output is correct |
14 |
Correct |
324 ms |
18560 KB |
Output is correct |
15 |
Correct |
319 ms |
16356 KB |
Output is correct |
16 |
Correct |
240 ms |
15056 KB |
Output is correct |
17 |
Correct |
266 ms |
16068 KB |
Output is correct |
18 |
Correct |
94 ms |
9120 KB |
Output is correct |
19 |
Correct |
327 ms |
18380 KB |
Output is correct |
20 |
Correct |
357 ms |
18512 KB |
Output is correct |
21 |
Correct |
338 ms |
18360 KB |
Output is correct |
22 |
Correct |
218 ms |
14780 KB |
Output is correct |
23 |
Correct |
201 ms |
13856 KB |
Output is correct |
24 |
Correct |
61 ms |
8760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
9 ms |
1620 KB |
Output is correct |
8 |
Correct |
10 ms |
1624 KB |
Output is correct |
9 |
Correct |
10 ms |
1696 KB |
Output is correct |
10 |
Correct |
7 ms |
1108 KB |
Output is correct |
11 |
Correct |
6 ms |
1108 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
9 ms |
1372 KB |
Output is correct |
14 |
Correct |
10 ms |
1432 KB |
Output is correct |
15 |
Correct |
9 ms |
1364 KB |
Output is correct |
16 |
Correct |
5 ms |
980 KB |
Output is correct |
17 |
Correct |
6 ms |
1108 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
288 ms |
13756 KB |
Output is correct |
20 |
Correct |
321 ms |
16280 KB |
Output is correct |
21 |
Correct |
288 ms |
16304 KB |
Output is correct |
22 |
Correct |
211 ms |
14160 KB |
Output is correct |
23 |
Correct |
247 ms |
14984 KB |
Output is correct |
24 |
Correct |
87 ms |
9180 KB |
Output is correct |
25 |
Correct |
288 ms |
16032 KB |
Output is correct |
26 |
Correct |
272 ms |
16056 KB |
Output is correct |
27 |
Correct |
255 ms |
15712 KB |
Output is correct |
28 |
Correct |
223 ms |
14836 KB |
Output is correct |
29 |
Correct |
195 ms |
13840 KB |
Output is correct |
30 |
Correct |
60 ms |
8808 KB |
Output is correct |
31 |
Correct |
392 ms |
18384 KB |
Output is correct |
32 |
Correct |
324 ms |
18560 KB |
Output is correct |
33 |
Correct |
319 ms |
16356 KB |
Output is correct |
34 |
Correct |
240 ms |
15056 KB |
Output is correct |
35 |
Correct |
266 ms |
16068 KB |
Output is correct |
36 |
Correct |
94 ms |
9120 KB |
Output is correct |
37 |
Correct |
327 ms |
18380 KB |
Output is correct |
38 |
Correct |
357 ms |
18512 KB |
Output is correct |
39 |
Correct |
338 ms |
18360 KB |
Output is correct |
40 |
Correct |
218 ms |
14780 KB |
Output is correct |
41 |
Correct |
201 ms |
13856 KB |
Output is correct |
42 |
Correct |
61 ms |
8760 KB |
Output is correct |
43 |
Correct |
649 ms |
43764 KB |
Output is correct |
44 |
Correct |
618 ms |
43708 KB |
Output is correct |
45 |
Correct |
628 ms |
43976 KB |
Output is correct |
46 |
Correct |
316 ms |
22572 KB |
Output is correct |
47 |
Correct |
352 ms |
24784 KB |
Output is correct |
48 |
Correct |
98 ms |
8880 KB |
Output is correct |
49 |
Correct |
595 ms |
43696 KB |
Output is correct |
50 |
Correct |
566 ms |
43776 KB |
Output is correct |
51 |
Correct |
505 ms |
43888 KB |
Output is correct |
52 |
Correct |
326 ms |
24488 KB |
Output is correct |
53 |
Correct |
255 ms |
19900 KB |
Output is correct |