답안 #126979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
126979 2019-07-08T17:30:45 Z MohamedAhmed04 Examination (JOI19_examination) C++14
100 / 100
2343 ms 222340 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int , pair<int , int> > , null_type, less<pair<int , pair<int , int> > >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 1e6 + 5;

ordered_set bit[N];

void update(int x, int y , int idx)
{
	for(int i = x; i < N; i += i & -i)
		bit[i].insert({y, {x , idx}});
}
int query(int x, int y)
{
	int ans = 0;
	for(int i = x; i > 0; i -= i & -i)
    {
        ans += bit[i].order_of_key({y+1, {0 , -1}});
    }
	return ans;
}
/*int query(int x , int y)
{
    int ans = 0 ;
    while(x > 0)
    {
        int y1 = y ;
        while(y1 > 0)
        {
            ans += bit[{x , y1}] ;
            y1 -= (y1 & -y1) ;
        }
        x -= (x & -x) ;
    }
    return ans ;
}*/

int a[N], b[N] , ans[N];
int qa[N] , qb[N] , qc[N] , was[N] , was2[N];

vector<int>v ;
int n , q ;

void compress()
{
    sort(v.begin() , v.end()) ;
    v.erase(unique(v.begin() , v.end()) , v.end()) ;
    for(int i = 0 ; i < n ; ++i)
    {
        int x = lower_bound(v.begin() , v.end() , a[i]) - v.begin() ;
        int y = lower_bound(v.begin() , v.end() , b[i]) - v.begin() ;
        x += 2 ;
        y += 2 ;
        was[x] = a[i] ;
        was[y] = b[i] ;
        a[i] = x ;
        b[i] = y ;
    }
    for(int i = 0 ; i < q ; ++i)
    {
        int x = lower_bound(v.begin() , v.end() , qa[i]) - v.begin() ;
        int y = lower_bound(v.begin() , v.end() , qb[i]) - v.begin() ;
        int z = lower_bound(v.begin() , v.end() , qc[i]) - v.begin() ;
        x += 2 ;
        y += 2 ;
        //z += 4 ;
        was2[x] = qa[i] ;
        was2[y] = qb[i] ;
        //was2[z] = qc[i] ;
        qa[i] = x ;
        qb[i] = y ;
        //qc[i] = z ;
    }
    return ;
}

int main()
{
    scanf("%d %d" , &n, &q) ;
    vector< pair<int , int> >vp ;
    vector< pair<int , pair<int , pair<int , int> > > >vp2 ;
    for(int i = 0 ; i < n ; ++i)
    {
        cin>>a[i]>>b[i] ;
        a[i] += 2 ;
        b[i] += 2 ;
        v.push_back(a[i]) ;
        v.push_back(b[i]) ;
        //vp.push_back({a[i] , b[i]}) ;
    }
    for(int i = 0 ; i < q ; ++i)
    {
        int x , y , z ;
        cin>>x>>y>>z ;
        x += 2 ;
        y += 2 ;
        z += 4 ;
        qa[i] = x ;
        qb[i] = y ;
        qc[i] = z ;
        v.push_back(qa[i]) ;
        v.push_back(qb[i]) ;
        //v.push_back(qc[i]) ;
        //vp2.push_back({x , {y , {z , i}}}) ;
        //cout<<query(N-1 , N-1 , z) - query(x-1 , N-1 , z) - query(N-1 , y-1 , z) + query(x-1 , y-1 , z)<<"\n";
    }
    compress() ;
    for(int i = 0 ; i < n ; ++i)
    {
        //cout<<was[a[i]]<<" "<<was[b[i]]<<"\n";
        //cout<<was[a[i]]<<" "<<was[b[i]]<<"\n";
        vp.push_back({a[i] , b[i]}) ;
    }
    //for(int i = 0 ; i < q ; ++i)
    //    cout<<was2[qa[i]]<<" "<<was2[qb[i]]<<" "<<was2[qc[i]]<<"\n";
    for(int i = 0 ; i < q ; ++i)
    {
        vp2.push_back({qa[i] , {qb[i] , {qc[i] , i}}}) ;
    }
    sort(vp.begin() , vp.end()) ;
    reverse(vp.begin() , vp.end()) ;
    sort(vp2.begin() , vp2.end()) ;
    reverse(vp2.begin() , vp2.end()) ;
    int idx = 0 ;
    const int N2 = 2e9+10 ;
    for(int i = 0 ; i < q ; ++i)
    {
        while(idx < n && vp[idx].first >= vp2[i].first)
        {
            //cout<<vp[idx].second<<" "<<was[vp[idx].first] + was[vp[idx].second]<<"\n";
            update(vp[idx].second , was[vp[idx].first] + was[vp[idx].second] , idx) ;
            idx++ ;
        }
        int idxx = vp2[i].second.second.second ;
        int x = vp2[i].second.first , y = vp2[i].second.second.first ;
        ans[idxx] = query(N-1 , N2-1) - query(x-1 , N2-1) - query(N-1 , y-1) + query(x-1 , y-1) ;
    }
    for(int i = 0 ; i < q ; ++i)
        cout<<ans[i]<<"\n";
    return 0 ;
}

Compilation message

examination.cpp: In function 'void compress()':
examination.cpp:67:13: warning: unused variable 'z' [-Wunused-variable]
         int z = lower_bound(v.begin() , v.end() , qc[i]) - v.begin() ;
             ^
examination.cpp: In function 'int main()':
examination.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d" , &n, &q) ;
     ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 94328 KB Output is correct
2 Correct 125 ms 94412 KB Output is correct
3 Correct 123 ms 94328 KB Output is correct
4 Correct 122 ms 94456 KB Output is correct
5 Correct 123 ms 94356 KB Output is correct
6 Correct 122 ms 94328 KB Output is correct
7 Correct 156 ms 97144 KB Output is correct
8 Correct 155 ms 97144 KB Output is correct
9 Correct 154 ms 97120 KB Output is correct
10 Correct 186 ms 97912 KB Output is correct
11 Correct 151 ms 97208 KB Output is correct
12 Correct 154 ms 97920 KB Output is correct
13 Correct 165 ms 97400 KB Output is correct
14 Correct 157 ms 97324 KB Output is correct
15 Correct 153 ms 97272 KB Output is correct
16 Correct 147 ms 97224 KB Output is correct
17 Correct 164 ms 98268 KB Output is correct
18 Correct 170 ms 98236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1822 ms 176264 KB Output is correct
2 Correct 1796 ms 176084 KB Output is correct
3 Correct 1836 ms 176048 KB Output is correct
4 Correct 1461 ms 215656 KB Output is correct
5 Correct 1089 ms 177128 KB Output is correct
6 Correct 1276 ms 215076 KB Output is correct
7 Correct 1884 ms 176716 KB Output is correct
8 Correct 1680 ms 176488 KB Output is correct
9 Correct 1632 ms 176732 KB Output is correct
10 Correct 991 ms 177000 KB Output is correct
11 Correct 1406 ms 220600 KB Output is correct
12 Correct 1847 ms 219860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1822 ms 176264 KB Output is correct
2 Correct 1796 ms 176084 KB Output is correct
3 Correct 1836 ms 176048 KB Output is correct
4 Correct 1461 ms 215656 KB Output is correct
5 Correct 1089 ms 177128 KB Output is correct
6 Correct 1276 ms 215076 KB Output is correct
7 Correct 1884 ms 176716 KB Output is correct
8 Correct 1680 ms 176488 KB Output is correct
9 Correct 1632 ms 176732 KB Output is correct
10 Correct 991 ms 177000 KB Output is correct
11 Correct 1406 ms 220600 KB Output is correct
12 Correct 1847 ms 219860 KB Output is correct
13 Correct 1983 ms 175996 KB Output is correct
14 Correct 2032 ms 178904 KB Output is correct
15 Correct 1860 ms 178612 KB Output is correct
16 Correct 1637 ms 217804 KB Output is correct
17 Correct 1226 ms 179004 KB Output is correct
18 Correct 1290 ms 216104 KB Output is correct
19 Correct 2024 ms 178848 KB Output is correct
20 Correct 2033 ms 179020 KB Output is correct
21 Correct 2045 ms 179208 KB Output is correct
22 Correct 1000 ms 178552 KB Output is correct
23 Correct 1427 ms 222340 KB Output is correct
24 Correct 1830 ms 220720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 94328 KB Output is correct
2 Correct 125 ms 94412 KB Output is correct
3 Correct 123 ms 94328 KB Output is correct
4 Correct 122 ms 94456 KB Output is correct
5 Correct 123 ms 94356 KB Output is correct
6 Correct 122 ms 94328 KB Output is correct
7 Correct 156 ms 97144 KB Output is correct
8 Correct 155 ms 97144 KB Output is correct
9 Correct 154 ms 97120 KB Output is correct
10 Correct 186 ms 97912 KB Output is correct
11 Correct 151 ms 97208 KB Output is correct
12 Correct 154 ms 97920 KB Output is correct
13 Correct 165 ms 97400 KB Output is correct
14 Correct 157 ms 97324 KB Output is correct
15 Correct 153 ms 97272 KB Output is correct
16 Correct 147 ms 97224 KB Output is correct
17 Correct 164 ms 98268 KB Output is correct
18 Correct 170 ms 98236 KB Output is correct
19 Correct 1822 ms 176264 KB Output is correct
20 Correct 1796 ms 176084 KB Output is correct
21 Correct 1836 ms 176048 KB Output is correct
22 Correct 1461 ms 215656 KB Output is correct
23 Correct 1089 ms 177128 KB Output is correct
24 Correct 1276 ms 215076 KB Output is correct
25 Correct 1884 ms 176716 KB Output is correct
26 Correct 1680 ms 176488 KB Output is correct
27 Correct 1632 ms 176732 KB Output is correct
28 Correct 991 ms 177000 KB Output is correct
29 Correct 1406 ms 220600 KB Output is correct
30 Correct 1847 ms 219860 KB Output is correct
31 Correct 1983 ms 175996 KB Output is correct
32 Correct 2032 ms 178904 KB Output is correct
33 Correct 1860 ms 178612 KB Output is correct
34 Correct 1637 ms 217804 KB Output is correct
35 Correct 1226 ms 179004 KB Output is correct
36 Correct 1290 ms 216104 KB Output is correct
37 Correct 2024 ms 178848 KB Output is correct
38 Correct 2033 ms 179020 KB Output is correct
39 Correct 2045 ms 179208 KB Output is correct
40 Correct 1000 ms 178552 KB Output is correct
41 Correct 1427 ms 222340 KB Output is correct
42 Correct 1830 ms 220720 KB Output is correct
43 Correct 2098 ms 177036 KB Output is correct
44 Correct 2050 ms 177184 KB Output is correct
45 Correct 2043 ms 172312 KB Output is correct
46 Correct 1711 ms 216736 KB Output is correct
47 Correct 1278 ms 173784 KB Output is correct
48 Correct 1327 ms 214796 KB Output is correct
49 Correct 2343 ms 170844 KB Output is correct
50 Correct 1792 ms 170956 KB Output is correct
51 Correct 1960 ms 168892 KB Output is correct
52 Correct 1103 ms 173672 KB Output is correct
53 Correct 2067 ms 221628 KB Output is correct