# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
398197 |
2021-05-03T22:49:14 Z |
duality |
Fire (JOI20_ho_t5) |
C++11 |
|
863 ms |
66028 KB |
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
#pragma GCC optimize("Ofast")
int S[200000],l[200000],r[200000];
LLI ans[200000];
struct event { int y,l,r,t,i; };
bool comp(event a,event b) {
if (a.y == b.y) return abs(a.t) > abs(b.t);
else return a.y < b.y;
}
vector<event> v1,v2;
vi s;
LLI bit1[400001],bit2[400001];
int update(int s,int e,int num,int N) {
int i;
for (i = s+1; i <= N; i += i & (-i)) bit1[i] += num,bit2[i] -= (LLI) (s-1)*num;
for (i = e+1; i <= N; i += i & (-i)) bit1[i] -= num,bit2[i] += (LLI) e*num;
return 0;
}
LLI query(int s,int e) {
int i;
LLI ans = 0;
for (i = e+1; i > 0; i -= i & (-i)) ans += bit1[i]*e+bit2[i];
for (i = s; i > 0; i -= i & (-i)) ans -= bit1[i]*(s-1)+bit2[i];
return ans;
}
int main() {
int i;
int N,Q,T,L,R;
scanf("%d %d",&N,&Q);
for (i = 0; i < N; i++) scanf("%d",&S[i]);
for (i = 0; i < Q; i++) {
scanf("%d %d %d",&T,&L,&R);
L--,R--;
v1.pb((event){T,L,R,0,i});
v2.pb((event){T,L-T,R-T,0,i});
}
for (i = 0; i < N; i++) {
while (!s.empty() && (S[s.back()] < S[i])) s.pop_back();
if (s.empty()) l[i] = -1;
else l[i] = s.back();
s.pb(i);
}
s.clear();
for (i = N-1; i >= 0; i--) {
while (!s.empty() && (S[s.back()] <= S[i])) s.pop_back();
if (s.empty()) r[i] = N;
else r[i] = s.back();
s.pb(i);
}
for (i = 0; i < N; i++) {
v1.pb((event){r[i]-i,i,r[i]-1,S[i],0});
v1.pb((event){0,i,N-1,S[i],0});
v1.pb((event){r[i]-i,i,N-1,-S[i],0});
v2.pb((event){0,i+1,N-1,-S[i],0});
v2.pb((event){r[i]-i,i+1,N-1,S[i],0});
if (l[i] != -1) {
v1.pb((event){r[i]-l[i]-1,i,r[i]-1,-S[i],0});
v1.pb((event){i-l[i],i,N-1,-S[i],0});
v1.pb((event){r[i]-l[i]-1,i,N-1,S[i],0});
v2.pb((event){i-l[i],l[i]+1,N-1,S[i],0});
v2.pb((event){r[i]-l[i]-1,l[i]+1,N-1,-S[i],0});
}
}
sort(v1.begin(),v1.end(),comp);
sort(v2.begin(),v2.end(),comp);
for (i = 0; i < v1.size(); i++) {
if (v1[i].t != 0) update(v1[i].l+N,v1[i].r+N,v1[i].t,2*N);
else ans[v1[i].i] += query(v1[i].l+N,v1[i].r+N);
}
for (i = 0; i <= 2*N; i++) bit1[i] = bit2[i] = 0;
for (i = 0; i < v2.size(); i++) {
if (v2[i].t != 0) update(v2[i].l+N,v2[i].r+N,v2[i].t,2*N);
else ans[v2[i].i] += query(v2[i].l+N,v2[i].r+N);
}
for (i = 0; i < Q; i++) printf("%lld\n",ans[i]);
return 0;
}
Compilation message
ho_t5.cpp: In function 'int main()':
ho_t5.cpp:123:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | for (i = 0; i < v1.size(); i++) {
| ~~^~~~~~~~~~~
ho_t5.cpp:128:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
128 | for (i = 0; i < v2.size(); i++) {
| ~~^~~~~~~~~~~
ho_t5.cpp:85:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
85 | scanf("%d %d",&N,&Q);
| ~~~~~^~~~~~~~~~~~~~~
ho_t5.cpp:86:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
86 | for (i = 0; i < N; i++) scanf("%d",&S[i]);
| ~~~~~^~~~~~~~~~~~
ho_t5.cpp:88:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
88 | scanf("%d %d %d",&T,&L,&R);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
777 ms |
58912 KB |
Output is correct |
3 |
Correct |
768 ms |
64444 KB |
Output is correct |
4 |
Correct |
782 ms |
64512 KB |
Output is correct |
5 |
Correct |
804 ms |
65516 KB |
Output is correct |
6 |
Correct |
781 ms |
64740 KB |
Output is correct |
7 |
Correct |
786 ms |
65204 KB |
Output is correct |
8 |
Correct |
795 ms |
65672 KB |
Output is correct |
9 |
Correct |
800 ms |
65276 KB |
Output is correct |
10 |
Correct |
776 ms |
64396 KB |
Output is correct |
11 |
Correct |
802 ms |
65780 KB |
Output is correct |
12 |
Correct |
781 ms |
64356 KB |
Output is correct |
13 |
Correct |
800 ms |
65144 KB |
Output is correct |
14 |
Correct |
792 ms |
64960 KB |
Output is correct |
15 |
Correct |
838 ms |
65168 KB |
Output is correct |
16 |
Correct |
803 ms |
64540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
799 ms |
58752 KB |
Output is correct |
3 |
Correct |
796 ms |
64192 KB |
Output is correct |
4 |
Correct |
837 ms |
65000 KB |
Output is correct |
5 |
Correct |
793 ms |
64168 KB |
Output is correct |
6 |
Correct |
808 ms |
64172 KB |
Output is correct |
7 |
Correct |
833 ms |
64312 KB |
Output is correct |
8 |
Correct |
824 ms |
64316 KB |
Output is correct |
9 |
Correct |
833 ms |
64180 KB |
Output is correct |
10 |
Correct |
830 ms |
64128 KB |
Output is correct |
11 |
Correct |
821 ms |
64856 KB |
Output is correct |
12 |
Correct |
863 ms |
64192 KB |
Output is correct |
13 |
Correct |
823 ms |
64496 KB |
Output is correct |
14 |
Correct |
815 ms |
64224 KB |
Output is correct |
15 |
Correct |
843 ms |
64632 KB |
Output is correct |
16 |
Correct |
831 ms |
64188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
636 ms |
59488 KB |
Output is correct |
2 |
Correct |
642 ms |
63552 KB |
Output is correct |
3 |
Correct |
656 ms |
63656 KB |
Output is correct |
4 |
Correct |
636 ms |
63700 KB |
Output is correct |
5 |
Correct |
637 ms |
63648 KB |
Output is correct |
6 |
Correct |
627 ms |
63564 KB |
Output is correct |
7 |
Correct |
652 ms |
63552 KB |
Output is correct |
8 |
Correct |
658 ms |
63644 KB |
Output is correct |
9 |
Correct |
639 ms |
63576 KB |
Output is correct |
10 |
Correct |
645 ms |
63532 KB |
Output is correct |
11 |
Correct |
649 ms |
63656 KB |
Output is correct |
12 |
Correct |
644 ms |
63664 KB |
Output is correct |
13 |
Correct |
659 ms |
63660 KB |
Output is correct |
14 |
Correct |
654 ms |
63812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
777 ms |
58912 KB |
Output is correct |
34 |
Correct |
768 ms |
64444 KB |
Output is correct |
35 |
Correct |
782 ms |
64512 KB |
Output is correct |
36 |
Correct |
804 ms |
65516 KB |
Output is correct |
37 |
Correct |
781 ms |
64740 KB |
Output is correct |
38 |
Correct |
786 ms |
65204 KB |
Output is correct |
39 |
Correct |
795 ms |
65672 KB |
Output is correct |
40 |
Correct |
800 ms |
65276 KB |
Output is correct |
41 |
Correct |
776 ms |
64396 KB |
Output is correct |
42 |
Correct |
802 ms |
65780 KB |
Output is correct |
43 |
Correct |
781 ms |
64356 KB |
Output is correct |
44 |
Correct |
800 ms |
65144 KB |
Output is correct |
45 |
Correct |
792 ms |
64960 KB |
Output is correct |
46 |
Correct |
838 ms |
65168 KB |
Output is correct |
47 |
Correct |
803 ms |
64540 KB |
Output is correct |
48 |
Correct |
799 ms |
58752 KB |
Output is correct |
49 |
Correct |
796 ms |
64192 KB |
Output is correct |
50 |
Correct |
837 ms |
65000 KB |
Output is correct |
51 |
Correct |
793 ms |
64168 KB |
Output is correct |
52 |
Correct |
808 ms |
64172 KB |
Output is correct |
53 |
Correct |
833 ms |
64312 KB |
Output is correct |
54 |
Correct |
824 ms |
64316 KB |
Output is correct |
55 |
Correct |
833 ms |
64180 KB |
Output is correct |
56 |
Correct |
830 ms |
64128 KB |
Output is correct |
57 |
Correct |
821 ms |
64856 KB |
Output is correct |
58 |
Correct |
863 ms |
64192 KB |
Output is correct |
59 |
Correct |
823 ms |
64496 KB |
Output is correct |
60 |
Correct |
815 ms |
64224 KB |
Output is correct |
61 |
Correct |
843 ms |
64632 KB |
Output is correct |
62 |
Correct |
831 ms |
64188 KB |
Output is correct |
63 |
Correct |
636 ms |
59488 KB |
Output is correct |
64 |
Correct |
642 ms |
63552 KB |
Output is correct |
65 |
Correct |
656 ms |
63656 KB |
Output is correct |
66 |
Correct |
636 ms |
63700 KB |
Output is correct |
67 |
Correct |
637 ms |
63648 KB |
Output is correct |
68 |
Correct |
627 ms |
63564 KB |
Output is correct |
69 |
Correct |
652 ms |
63552 KB |
Output is correct |
70 |
Correct |
658 ms |
63644 KB |
Output is correct |
71 |
Correct |
639 ms |
63576 KB |
Output is correct |
72 |
Correct |
645 ms |
63532 KB |
Output is correct |
73 |
Correct |
649 ms |
63656 KB |
Output is correct |
74 |
Correct |
644 ms |
63664 KB |
Output is correct |
75 |
Correct |
659 ms |
63660 KB |
Output is correct |
76 |
Correct |
654 ms |
63812 KB |
Output is correct |
77 |
Correct |
832 ms |
64436 KB |
Output is correct |
78 |
Correct |
837 ms |
65392 KB |
Output is correct |
79 |
Correct |
836 ms |
65288 KB |
Output is correct |
80 |
Correct |
834 ms |
64332 KB |
Output is correct |
81 |
Correct |
856 ms |
64324 KB |
Output is correct |
82 |
Correct |
838 ms |
65004 KB |
Output is correct |
83 |
Correct |
825 ms |
64596 KB |
Output is correct |
84 |
Correct |
821 ms |
64308 KB |
Output is correct |
85 |
Correct |
847 ms |
65276 KB |
Output is correct |
86 |
Correct |
813 ms |
64280 KB |
Output is correct |
87 |
Correct |
848 ms |
65692 KB |
Output is correct |
88 |
Correct |
835 ms |
65840 KB |
Output is correct |
89 |
Correct |
806 ms |
64284 KB |
Output is correct |
90 |
Correct |
849 ms |
65328 KB |
Output is correct |
91 |
Correct |
810 ms |
64320 KB |
Output is correct |
92 |
Correct |
805 ms |
64296 KB |
Output is correct |
93 |
Correct |
813 ms |
64600 KB |
Output is correct |
94 |
Correct |
855 ms |
66028 KB |
Output is correct |
95 |
Correct |
845 ms |
65864 KB |
Output is correct |
96 |
Correct |
819 ms |
64624 KB |
Output is correct |
97 |
Correct |
833 ms |
64736 KB |
Output is correct |
98 |
Correct |
822 ms |
64052 KB |
Output is correct |
99 |
Correct |
829 ms |
64308 KB |
Output is correct |
100 |
Correct |
827 ms |
64880 KB |
Output is correct |
101 |
Correct |
830 ms |
64028 KB |
Output is correct |
102 |
Correct |
838 ms |
65284 KB |
Output is correct |