Submission #796835

#TimeUsernameProblemLanguageResultExecution timeMemory
796835vjudge1Misspelling (JOI22_misspelling)C++17
100 / 100
1568 ms304244 KiB


// Author : حسن

#include <bits/stdc++.h>



using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 5e5 + 9 , mod = 1e9 + 7;
ll c[N] = {} , dp[N][30] = {} , a[N] = {}, b[N] = {} , d[N][30] = {};
vector<int>v[N] , v1[N];

void sum(ll &x , ll y){
    x += y;
    if(x >= mod)
        x -= mod;
    else if(x < 0)
        x += mod;
}

void solve(){
    ll q , i , j , m , n , z , s  = 0, f, l , r , k , x , y , mn  = 1e18 , mx = 0;
    cin>>n>>m;
    for(i = 1; i <= m; i++){
        cin>>x>>y;
        if(x != y)
            if(x < y)
                v[x].pb(y);
            else
                v1[y].pb(x);
    }
    for(i = 1; i <= 26; i++)
        dp[1][i] = d[1][i] = 1;
    set<pair<int,int>>st , st1;
    for(i = 2; i <= n; i++){
            l = r = 0;
        for(auto to : v[i - 1])
            st.insert({i - 1 , to});
        for(auto to : v1[i - 1])
            st1.insert({i- 1 , to});
        while(st.size() && (--st.end())->se < i)
            st.erase(--st.end());
        while(st1.size() && (--st1.end())->se < i)
            st1.erase(--st1.end());
        if(st.size() != 0)
            l = (--st.end())->fi;
        if(st1.size() != 0)
            r = (--st1.end())->fi;
        mx = max(l , r);
    for(j = 1; j <= 26; j++){
        for(k= 1; k < j; k++){
            sum(dp[i][j],d[i - 1][k] - d[mx][k]);
            if(l < r)
                sum(dp[i][j] , d[r][k] - d[l][k]);
        }
        for(k= j + 1; k <= 26; k++){
            sum(dp[i][j],d[i - 1][k] - d[mx][k]);
            if(l > r)
                sum(dp[i][j] , d[l][k] - d[r][k]);
        }
        sum(d[i][j] ,d[i - 1][j]);
        sum(d[i][j] , dp[i][j]);
    }


    }
    s = 0;
    for(j = 1; j <= 26; j++)
        sum(s , d[n][j]);
    cout<<s;
}

int main(){
    /*
     TL;
     #ifndef ONLINE_JUDGE
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
     #endif
     */
int t = 1;
//cin>>t;

while(t--)
     {
     solve();
     }

}
// Author : حسن

Compilation message (stderr)

misspelling.cpp: In function 'void solve()':
misspelling.cpp:44:11: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   44 |         if(x != y)
      |           ^
misspelling.cpp:40:8: warning: unused variable 'q' [-Wunused-variable]
   40 |     ll q , i , j , m , n , z , s  = 0, f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |        ^
misspelling.cpp:40:28: warning: unused variable 'z' [-Wunused-variable]
   40 |     ll q , i , j , m , n , z , s  = 0, f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                            ^
misspelling.cpp:40:40: warning: unused variable 'f' [-Wunused-variable]
   40 |     ll q , i , j , m , n , z , s  = 0, f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                        ^
misspelling.cpp:40:63: warning: unused variable 'mn' [-Wunused-variable]
   40 |     ll q , i , j , m , n , z , s  = 0, f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                               ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...