Submission #1158252

#TimeUsernameProblemLanguageResultExecution timeMemory
1158252achiFoehn Phenomena (JOI17_foehn_phenomena)C++20
30 / 100
1098 ms15984 KiB
#include <bits/stdc++.h> using namespace std; int main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int N, Q, S, T; long long int L, R, X; long long int i, j; long long int deg = 0; scanf("%lld %lld %lld %lld", &N, &Q, &S, &T); vector<long long int> altitiudes(N+1); vector<tuple<long long int, long long int, long long int>> days(Q); unordered_set<int> updated; for (i = 0; i < N+1; i++) { scanf("%lld", &altitiudes[i]); if (i == 0) continue; if (altitiudes[i-1] < altitiudes[i]) { deg += (altitiudes[i-1] - altitiudes[i])*S; } else { deg += (altitiudes[i-1] - altitiudes[i])*T; } } for (i = 0; i < Q; i++) { scanf("%lld %lld %lld", &L, &R, &X); days[i] = {L, R, X}; } for (i = 0; i < Q; i++) { tie(L, R, X) = days[i]; if (L-1 >= 0) { if (altitiudes[L-1] < altitiudes[L]) { deg -= (altitiudes[L-1] - altitiudes[L])*S; } else { deg -= (altitiudes[L-1] - altitiudes[L])*T; } if (altitiudes[L-1] < (altitiudes[L] + X)) { deg += (altitiudes[L-1] - (altitiudes[L] + X))*S; } else { deg += (altitiudes[L-1] - (altitiudes[L] + X))*T; } } if (R+1 <= N) { if (altitiudes[R] < altitiudes[R+1]) { deg -= (altitiudes[R] - altitiudes[R+1])*S; } else { deg -= (altitiudes[R] - altitiudes[R+1])*T; } if ((altitiudes[R] + X) < altitiudes[R+1]) { deg += ((altitiudes[R] + X) - altitiudes[R+1])*S; } else { deg += ((altitiudes[R] + X) - altitiudes[R+1])*T; } } updated.clear(); for (j = i+1; j < Q; j++) { if (L <= get<0>(days[j])-1 && get<0>(days[j])-1 <= R && updated.find(get<0>(days[j])-1) == updated.end()) { altitiudes[get<0>(days[j])-1] += X; updated.insert(get<0>(days[j])-1); } if (L <= get<0>(days[j]) && get<0>(days[j]) <= R && updated.find(get<0>(days[j])) == updated.end()) { altitiudes[get<0>(days[j])] += X; updated.insert(get<0>(days[j])); } if (L <= get<0>(days[j])+1 && get<0>(days[j])+1 <= R && updated.find(get<0>(days[j])+1) == updated.end()) { altitiudes[get<0>(days[j])+1] += X; updated.insert(get<0>(days[j])+1); } if (L <= get<1>(days[j])-1 && get<1>(days[j])-1 <= R && updated.find(get<1>(days[j])-1) == updated.end()) { altitiudes[get<1>(days[j])-1] += X; updated.insert(get<1>(days[j])-1); } if (L <= get<1>(days[j]) && get<1>(days[j]) <= R && updated.find(get<1>(days[j])) == updated.end()) { altitiudes[get<1>(days[j])] += X; updated.insert(get<1>(days[j])); } if (L <= get<1>(days[j])+1 && get<1>(days[j])+1 <= R && updated.find(get<1>(days[j])+1) == updated.end()) { altitiudes[get<1>(days[j])+1] += X; updated.insert(get<1>(days[j])+1); } } cout << deg << endl; } return 0; }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%lld %lld %lld %lld", &N, &Q, &S, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%lld", &altitiudes[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%lld %lld %lld", &L, &R, &X);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...