This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // tourist 的逆元模板 | |
| template <typename T> | |
| T inverse(T a, T m) { | |
| T u = 0, v = 1; | |
| while (a != 0) { | |
| T t = m / a; | |
| m -= t * a; swap(a, m); | |
| u -= t * v; swap(u, v); | |
| } | |
| assert(m == 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int mod1 = 1000000007, mod2 = 998244353; | |
| const int mod = mod1; | |
| #include <bits/stdc++.h> | |
| #include <type_traits> | |
| using namespace std; | |
| // Andrew He's modular-arithmetic class | |
| template <int MOD_> struct modnum { | |
| static constexpr int MOD = MOD_; | |
| static_assert(MOD_ > 0, "MOD must be positive"); | |
| private: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int mod1 = 1000000007, mod2 = 998244353; | |
| const int mod = mod1; | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // Andrew He's modular-arithmetic class | |
| template <int MOD_> struct modnum { | |
| static constexpr int MOD = MOD_; | |
| static_assert(MOD_ > 0, "MOD must be positive"); | |
| private: | |
| using ll = long long; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int mod1 = 1000000007, mod2 = 998244353; | |
| const int mod = mod1; | |
| #ifdef LOCAL | |
| //#define _GLIBCXX_DEBUG | |
| // #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效 | |
| #endif | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // Andrew He's modular-arithmetic class | |
| template <int MOD_> struct modnum { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int mod1 = 1000000007, mod2 = 998244353; | |
| const int mod = mod1; | |
| #ifdef LOCAL | |
| //#define _GLIBCXX_DEBUG | |
| // #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效 | |
| #endif | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // Andrew He's modular-arithmetic class | |
| template <int MOD_> struct modnum { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int mod1 = 1000000007, mod2 = 998244353; | |
| const int mod = mod1; | |
| #ifdef LOCAL | |
| //#define _GLIBCXX_DEBUG | |
| // #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效 | |
| #endif | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // Andrew He's modular-arithmetic class | |
| template <int MOD_> struct modnum { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int mod1 = 1000000007, mod2 = 998244353; | |
| const int mod = mod1; | |
| #ifdef LOCAL | |
| //#define _GLIBCXX_DEBUG | |
| // #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效 | |
| #endif | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // Andrew He's modular-arithmetic class | |
| template <int MOD_> struct modnum { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int mod1 = 1000000007, mod2 = 998244353; | |
| const int mod = mod1; | |
| #ifdef LOCAL | |
| //#define _GLIBCXX_DEBUG | |
| // #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效 | |
| #endif | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // Andrew He's modular-arithmetic class | |
| template <int MOD_> struct modnum { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int mod1 = 1000000007, mod2 = 998244353; | |
| const int mod = mod1; | |
| #ifdef LOCAL | |
| //#define _GLIBCXX_DEBUG | |
| // #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效 | |
| #endif | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // Andrew He's modular-arithmetic class | |
| template <int MOD_> struct modnum { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| auto solve = [](vi& h, int n) { | |
| vi L(n + 1), R(n + 1); | |
| // 严格递增的单调栈 | |
| vpii inc{{0, 0}}; // pair.first 表示高度,pair.second 表示下标。假设 h[0] = -INF。 | |
| assert(SZ(inc) == 1); | |
| for (int i = 1; i <= n; i++) { | |
| while (inc.back().first >= h[i]) { | |
| inc.pop_back(); | |
| } | |
| L[i] = inc.back().second + 1; //左闭 |