이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for (int i = s; i <= e; ++i)
#define rrep(i,s,e) for (int i = s; i >= e; --i)
#define pb push_back
#define fi first
#define se second
#define len(a) (int)a.size()
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
const int mod = 1e9+7;
int n, m, c[26][2] = {}, dp[(int)1e6][26] = {}, ans = 0;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
vii upd[n+1];
rep (i,1,m) {
int a, b; cin >> a >> b;
if (a<b) upd[a].pb({b,0});
else upd[b].pb({a,1});
}
vi f[2];
rrep (i,n,1) {
for (ii el : upd[i]) {
while (len(f[el.se]) && f[el.se].back()<=el.fi) {
rep (j,0,25) c[j][el.se] = (c[j][el.se]-dp[f[el.se].back()][j]+mod)%mod;
f[el.se].pop_back();
}
}
int s = 1;
rep (j,0,25) {
dp[i][j] = (dp[i][j]+s)%mod;
s = (s+c[j][0])%mod;
}
s = 0;
rrep (j,25,0) {
dp[i][j] = (dp[i][j]+s)%mod;
s = (s+c[j][1])%mod;
}
rep (j,0,25) {
c[j][0] = (c[j][0] + dp[i][j])%mod;
c[j][1] = (c[j][1] + dp[i][j])%mod;
}
f[0].pb(i), f[1].pb(i);
}
rep (i,0,25) ans = (ans + dp[1][i]) % mod;
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |