제출 #396872

#제출 시각아이디문제언어결과실행 시간메모리
396872dualityDungeon 3 (JOI21_ho_t5)C++11
11 / 100
4088 ms29280 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 ---------- int A[200000],B[200000],S[200000],T[200000],U[200000]; LLI pre[200001]; int l[200000],r[200000]; vi s; int sparse[200000][18],logg[200001]; int query(int s,int e) { int l = logg[e-s+1]; return max(sparse[s][l],sparse[e-(1 << l)+1][l]); } int main() { int i; int N,M; scanf("%d %d",&N,&M); for (i = 0; i < N; i++) scanf("%d",&A[i]),pre[i+1] = pre[i]+A[i]; for (i = 0; i < N; i++) scanf("%d",&B[i]); for (i = 0; i < M; i++) scanf("%d %d %d",&S[i],&T[i],&U[i]),S[i]--,T[i] -= 2; int j; for (i = 0; i < N; i++) { while (!s.empty() && (B[s.back()] > B[i])) s.pop_back(); if (s.empty()) l[i] = -1; else l[i] = s.back(); s.pb(i); } s.clear(); for (i = N-1; i >= 0; i--) { while (!s.empty() && (B[s.back()] >= B[i])) s.pop_back(); if (s.empty()) r[i] = N; else r[i] = s.back(); s.pb(i); } for (i = 0; i < N; i++) sparse[i][0] = A[i]; for (i = 1; (1 << i) <= N; i++) { for (j = 0; j <= N-(1 << i); j++) sparse[j][i] = max(sparse[j][i-1],sparse[j+(1 << (i-1))][i-1]); } for (i = 2; i <= N; i++) logg[i] = logg[i/2]+1; for (i = 0; i < M; i++) { if (query(S[i],T[i]) > U[i]) printf("-1\n"); else { LLI ans = 0; for (j = S[i]; j <= T[i]; j++) { if ((l[j] >= S[i]) && (r[j] <= T[i])) { LLI a = min(pre[j]-pre[l[j]],(LLI) U[i]); LLI b = min(pre[r[j]]-pre[j],(LLI) U[i]); ans += (a+b-min(a+b,(LLI) U[i]))*B[j]; } else if (l[j] >= S[i]) { LLI a = min(pre[j]-pre[l[j]],(LLI) U[i]); LLI b = min(pre[T[i]+1]-pre[j],(LLI) U[i]); ans += (a+b-min(a+b,(LLI) U[i]))*B[j]; } else if (r[j] <= T[i]) { LLI b = min(pre[r[j]]-pre[j],(LLI) U[i]); ans += b*B[j]; } else { LLI b = min(pre[T[i]+1]-pre[j],(LLI) U[i]); ans += b*B[j]; } } printf("%lld\n",ans); } } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:71:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   71 |     for (i = 0; i < N; i++) scanf("%d",&A[i]),pre[i+1] = pre[i]+A[i];
      |                             ~~~~~^~~~~~~~~~~~
Main.cpp:72:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   72 |     for (i = 0; i < N; i++) scanf("%d",&B[i]);
      |                             ~~~~~^~~~~~~~~~~~
Main.cpp:73:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   73 |     for (i = 0; i < M; i++) scanf("%d %d %d",&S[i],&T[i],&U[i]),S[i]--,T[i] -= 2;
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...