Submission #874707

#TimeUsernameProblemLanguageResultExecution timeMemory
874707aaron_dcoderBob (COCI14_bob)C++17
120 / 120
168 ms18080 KiB
#define NDEBUG #ifdef NDEBUG #define dbg(TXTMSG) if constexpr (false) cerr << "lol" #define dbgv(VARN) ((void)0) #define dbgfor(COND) if constexpr (false) for (COND) #else #define _GLIBCXX_DEBUG 1 #define _GLIBCXX_DEBUG_PEDANTIC 1 #pragma GCC optimize("trapv") #define dbg(TXTMSG) cerr << "\n" << TXTMSG #define dbgv(VARN) cerr << "\n" << #VARN << " = "<< VARN << ", line: " << __LINE__ << "\n" #define dbgfor(COND) for (COND) #endif #include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll,ll>; #define e0 first #define e1 second constexpr ll INFTY = 2e18; ll numrects(ll b, ll e, const vector<ll>& data) { ll s = e-b+1; vector<array<pll,12>> stable(s); for (ll i = 0; i < s; ++i) { stable[i][0] = {data[b+i], i+1}; } for (ll p = 1; p < 12; ++p) { for (ll i = 0; i+(1<<(p-1)) < s; ++i) { stable[i][p] = min(stable[i][p-1], stable[i+(1<<(p-1))][p-1]); } } ll o=0; for (ll i = 0; i < s; ++i) { ll currr = i+1; for (ll p = 11; p >= 0; --p) { //dbg(p << " " << stable[currr][p].e0); if (currr<s && stable[currr][p] >= pll{data[b+i], i+1}) { currr += (1<<p); } } ll currl = i-1; for (ll p = 11; p >= 0; --p) { if (( currl-(1<<p)+1>=0)&& stable[currl-(1<<p)+1][p] >= pll{data[b+i], i+1}) { currl -= (1<<p); } } dbg(i << ":" << currl << " " << currr); o += data[b+i]*(i-currl)*(currr-i); } return o; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); dbgv(numrects(0,3,{1,2,3,4})); ll N,M; cin >> N >> M; vector<vector<ll>> H(N,vector<ll>(M,-1)); set<ll> posheights; for (ll y = 0; y < N; ++y) { for (ll x = 0; x < M; ++x) { cin >> H[y][x]; } } ll outp=0; vector<ll> uprun(M,1); for (ll y = 0; y < N; ++y) { if (y!=0) { for (ll x = 0; x < M; ++x) { if (H[y][x]==H[y-1][x]) { uprun[x]++; } else { uprun[x]=1; } } } ll runstart=0; for (ll x = 1; x < M; ++x) { if (H[y][x]!=H[y][x-1]) { outp+=numrects(runstart,x-1, uprun); runstart=x; } } outp+=numrects(runstart,M-1,uprun); } cout << outp; }
#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...
#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...