Submission #547383

#TimeUsernameProblemLanguageResultExecution timeMemory
547383dualityMisspelling (JOI22_misspelling)C++17
100 / 100
635 ms114728 KiB
#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 ---------- #define MOD 1000000007 int lazy1[1 << 20],lazy2[1 << 20]; int build(int s,int e,int i) { if (s == e) { lazy1[i] = lazy2[i] = -1; return 0; } int mid = (s+e) / 2; build(s,mid,2*i+1),build(mid+1,e,2*i+2); lazy1[i] = lazy2[i] = -1; return 0; } int update(int s,int e,int as,int ae,int i,int t,int num) { if ((s > ae) || (e < as)) return 0; else if ((s >= as) && (e <= ae)) { if (t == 1) lazy1[i] = max(lazy1[i],num); else lazy2[i] = max(lazy2[i],num); return 0; } int mid = (s+e) / 2; update(s,mid,as,ae,2*i+1,t,num),update(mid+1,e,as,ae,2*i+2,t,num); return 0; } int l1[500000],l2[500000]; int process(int s,int e,int i) { if (s == e) { l1[s] = lazy1[i],l2[s] = lazy2[i]; return 0; } int mid = (s+e) / 2; lazy1[2*i+1] = max(lazy1[2*i+1],lazy1[i]); lazy1[2*i+2] = max(lazy1[2*i+2],lazy1[i]); lazy2[2*i+1] = max(lazy2[2*i+1],lazy2[i]); lazy2[2*i+2] = max(lazy2[2*i+2],lazy2[i]); process(s,mid,2*i+1),process(mid+1,e,2*i+2); return 0; } int dp[500000][26],pre[500001][26]; int main() { int i; int N,M,A,B; scanf("%d %d",&N,&M); build(0,N-1,0); for (i = 0; i < M; i++) { scanf("%d %d",&A,&B); A--,B--; if (A < B) update(0,N-1,A,B-1,0,1,A); else update(0,N-1,B,A-1,0,2,B); } process(0,N-1,0); int j,k; for (i = 0; i < 26; i++) dp[0][i] = pre[1][i] = 1; for (i = 1; i < N; i++) { j = 0; for (k = 0; k < 26; k++) { if (j == k) continue; if (j > k) dp[i][j] = ((LLI) dp[i][j]+pre[i][k]-pre[l1[i-1]+1][k]+MOD) % MOD; else dp[i][j] = ((LLI) dp[i][j]+pre[i][k]-pre[l2[i-1]+1][k]+MOD) % MOD; } for (j = 1; j < 26; j++) { dp[i][j] = dp[i][j-1]; dp[i][j] = ((LLI) dp[i][j]+pre[i][j-1]-pre[l1[i-1]+1][j-1]+MOD) % MOD; dp[i][j] = ((LLI) dp[i][j]-(pre[i][j]-pre[l2[i-1]+1][j])+MOD) % MOD; } for (j = 0; j < 26; j++) pre[i+1][j] = (pre[i][j]+dp[i][j]) % MOD; } int ans = 0; for (i = 0; i < 26; i++) ans = (ans+pre[N][i]) % MOD; printf("%d\n",ans); return 0; }

Compilation message (stderr)

misspelling.cpp: In function 'int main()':
misspelling.cpp:102:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
misspelling.cpp:105:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |         scanf("%d %d",&A,&B);
      |         ~~~~~^~~~~~~~~~~~~~~
#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...