# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1043712 | MarwenElarbi | Misspelling (JOI22_misspelling) | C++17 | 5 ms | 25176 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define pb push_back
#define fi first
#define se second
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int nax=5e5+5;
const int MOD=1e9+7;
int n,k;
long long dp[nax][26];
vector<int> up[nax];
vector<int> down[nax];
long long sum_up[26];
long long sum_down[26];
int main(){
optimise;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin>>n>>k;
for (int i = 0; i < k; ++i)
{
int x,y;
cin>>x>>y;
if(x==y) continue;
if(x>y){
up[y].pb(x);
}else{
down[x].pb(y);
}
}
for (int i = 0; i < 26; ++i)
{
dp[n][i]=1;
}
set<int> s,t;
for (int i = n-1; i >= 1; --i)
{
s.insert(i+1);
t.insert(i+1);
for (int j = 0; j < 26; ++j)
{
sum_up[j]+=dp[i+1][j];
sum_down[j]+=dp[i+1][j];
}
for(auto u:up[i]){
auto it=s.lower_bound(i+1);
while(it!=s.end() && (*it)<=u){
for (int j = 0; j < 26; ++j) sum_up[j]-=dp[(*it)][j];
it=s.erase(it);
}
}
for(auto u:down[i]){
auto it=t.lower_bound(i+1);
while(it!=t.end() && (*it)<=u){
for (int j = 0; j < 26; ++j) sum_down[j]-=dp[(*it)][j];
it=t.erase(it);
}
}
long long sum=0;
for (int j = 0; j < 26; ++j)
{
dp[i][j]+=sum;
sum+=sum_down[j];
}
sum=0;
for (int j = 25; j >= 0; --j)
{
dp[i][j]+=sum;
sum+=sum_up[j];
}
for (int j = 0; j < 26; ++j)
{
dp[i][j]++;
dp[i][j]%=MOD;
}
}
long long ans=0;
for (int i = 0; i < 26; ++i)
{
ans+=dp[1][i];
ans%=MOD;
}
cout <<ans<<endl;
}
Compilation message (stderr)
# | 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... |