#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 ];
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 );
}
vector <int> vv;
vector <pair<int, int> > v, v1;
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 ];
vv.push_back( a[ i ] );
vv.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 ];
vv.push_back( x[ i ] );
vv.push_back( y[ i ] );
}
sort( v.begin(), v.end() );
sort( vv.begin(), vv.end() );
for ( auto i : vv ) {
if ( !mp[ i ] )
mp[ i ] = ++num;
}
for ( int i = 1; i <= n; i ++ ) {
a[ i ] = mp[ a[ i ] ], b[ i ] = mp[ b[ i ] ];
}
for ( int i = 1; i <= m; i ++ ) {
x[ i ] = mp[ x[ i ] ];
y[ i ] = mp[ y[ i ] ];
v1.push_back( { z[ i ], 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;
}
for ( int i = 1; i <= m; i ++ )
cout << an[ i ] << " ";
}
Compilation message
examination.cpp:107:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
107 | main () {
| ^~~~
examination.cpp: In function 'int main()':
examination.cpp:140: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]
140 | while ( pos < v.size() && v[ pos ].first >= i.first ) {
| ~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
298 ms |
16728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
298 ms |
16728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |