File tree Expand file tree Collapse file tree 1 file changed +6
-15
lines changed Expand file tree Collapse file tree 1 file changed +6
-15
lines changed Original file line number Diff line number Diff line change @@ -19,22 +19,13 @@ int main() {
19
19
sort (B.begin (), B.end ());
20
20
sort (C.begin (), C.end ());
21
21
22
- vector<ll> DP (N, 0 );
23
- for (int i = 0 ; i < N; ++i) {
24
- auto it = lower_bound (A.begin (), A.end (), B[i]);
25
- int s = distance (A.begin (), it);
26
- DP[i] = s;
27
- }
28
- for (int i = 1 ; i < N; ++i) {
29
- DP[i] += DP[i-1 ];
30
- }
31
22
ll ans = 0 ;
32
- for (auto c : C ) {
33
- auto it = lower_bound (B .begin (), B .end (), c );
34
- int s = distance (B .begin (), it );
35
- if (s > 0 ) {
36
- ans += DP[s- 1 ] ;
37
- }
23
+ for (int i = 0 ; i < N; ++i ) {
24
+ auto ita = lower_bound (A .begin (), A .end (), B[i] );
25
+ int sa = distance (A .begin (), ita );
26
+ auto itb = upper_bound (C. begin (), C. end (), B[i]);
27
+ int sb = distance (itb, C. end ()) ;
28
+ ans += ll (sa) * sb;
38
29
}
39
30
cout << ans << endl;
40
31
You can’t perform that action at this time.
0 commit comments