Dang_Quan_10_Tin

Untitled

Mar 13th, 2020
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.18 KB | None | 0 0
  1. #define task "weight"
  2. using namespace std;
  3.  
  4. int typetest;
  5.  
  6. inline void fastIOfileinput(){
  7.     ios_base:: sync_with_stdio(0);
  8.     cin.tie(0);
  9.     cout.tie(0);
  10.     if(fopen(task".inp", "r")){
  11.         freopen(task".inp", "r", stdin);
  12.         freopen(task".out", "w", stdout);
  13.     }
  14.     if(fopen(task".in", "r")){
  15.         freopen(task".in", "r", stdin);
  16.         freopen(task".out", "w", stdout);
  17.     }
  18.     typetest = 0;
  19. }
  20.  
  21. const int N = 4e5 + 2;
  22. int m, n;
  23. int a[N], l[N], r[N], h[N], k[N];
  24. stack<int> s, q;
  25. int maxn[1000003];
  26. int minn[1000003];
  27.  
  28. inline void Enter(){
  29.     cin >> n;
  30.     for(int i = 1; i <= n; ++i)
  31.         cin >> a[i];
  32. }
  33. inline void solve(){
  34.     for(int i = 1; i <= n; ++i){
  35.         while(!s.empty() && a[i] <= a[s.top()])
  36.             s.pop();
  37.         l[i] = (s.empty() ? 0 : s.top());
  38.         s.push(i);
  39.         while(!q.empty() && a[i] >= a[q.top()])
  40.             q.pop();
  41.         h[i] = (q.empty() ? 0 : q.top());
  42.         q.push(i);
  43.     }
  44.     while(!s.empty()) s.pop();
  45.     while(!q.empty()) q.pop();
  46.     for(int i = n; i > 0; --i){
  47.         while(!s.empty() && a[i] <= a[s.top()])
  48.             s.pop();
  49.         r[i] = (s.empty() ? n + 1 : s.top());
  50.         s.push(i);
  51.         while(!q.empty() && a[i] >= a[q.top()])
  52.             q.pop();
  53.         k[i] = (q.empty() ? n + 1 : q.top());
  54.         q.push(i);
  55.     }
  56.     ll ans = 0;
  57.     for(int i = 1; i <= n; ++i){
  58. //      cerr << l[i] << " " << r[i] << "    " << h[i] << " " << k[i] << " ";
  59.         ans -= (ll)(i - max(l[i], maxn[a[i]]) ) * (r[i] - i) * a[i] - (ll)a[i];
  60.         maxn[a[i]] = i;
  61. //      cerr << "\n" << ans;
  62.         ans += (ll)(i - max(minn[a[i]], h[i]) ) * (k[i] - i) * a[i] - (ll)a[i];
  63. //      cerr << "\n" << ans << "\n";
  64.         minn[a[i]] = i;
  65.     }
  66.     cout << ans;
  67. }
  68.  
  69.  
  70.  
  71.  
  72. #define task "project"
  73. using namespace std;
  74.  
  75. int typetest;
  76.  
  77. inline void fastIOfileinput(){
  78.     ios_base:: sync_with_stdio(0);
  79.     cin.tie(0);
  80.     cout.tie(0);
  81.     if(fopen(task".inp", "r")){
  82.         freopen(task".inp", "r", stdin);
  83.         freopen(task".out", "w", stdout);
  84.     }
  85.     if(fopen(task".in", "r")){
  86.         freopen(task".in", "r", stdin);
  87.         freopen(task".out", "w", stdout);
  88.     }
  89.     typetest = 0;
  90. }
  91.  
  92. const int N = 4e5 + 2;
  93. int h, ss, d, n, k;
  94. int a[N];
  95.  
  96. inline void Enter(){
  97.     cin >> n >> h >> ss >> d;
  98.     for(int i = 1; i <= n; ++i)
  99.         cin >> a[i];
  100.     k = (int) ceil((ld)(h + d) * 1.0/ ss);
  101. }
  102. inline void solve(){
  103.     ll ans = (ll)(h) * a[1];
  104.     int b[N];
  105.     b[1] = a[1];
  106.     deque<int> s;
  107.     for(int i = 1; i <= min(k, n); ++i){
  108.         while(!s.empty() && a[s.back()] <= a[i])
  109.             s.pop_back();
  110.         s.pb(i);
  111.     }
  112.     for(int i = 1; i <= n; ++i){
  113.         while(!s.empty() && a[s.back()] <= a[min(i + k, n)])
  114.             s.pop_back();
  115.         while(!s.empty() && s.front() <= i)
  116.             s.pop_front();
  117.  
  118.         if(i + k <= n ) s.pb(i + k);
  119.         int M = a[s.front()];
  120. //      cerr << s.front() << " "  << M << "\n";
  121.         ans += (ll) b[i] * ss;
  122.         if(M >= b[i]){
  123.             b[i + 1] = b[i];
  124.             if(a[i + 1] > b[i]){
  125.                 ans += (ll) h * (a[i + 1] - b[i]);
  126.                 b[i + 1] = a[i + 1];
  127.             }
  128.         }
  129.         else{
  130.             ans += (ll) d * (b[i] - M);
  131.             b[i + 1] = M ;
  132.         }
  133.  
  134.     }
  135.     cout << ans + (ll) b[n] * d << "\n";
  136.     for(int i = 1; i <= n; ++i)
  137.         cout << b[i] << " ";
  138. }
  139.  
  140.  
  141.  
  142. #define task "cocktail"
  143. using namespace std;
  144.  
  145. int typetest;
  146.  
  147. inline void fastIOfileinput(){
  148.     ios_base:: sync_with_stdio(0);
  149.     cin.tie(0);
  150.     cout.tie(0);
  151.     if(fopen(task".inp", "r")){
  152.         freopen(task".inp", "r", stdin);
  153.         freopen(task".out", "w", stdout);
  154.     }
  155.     if(fopen(task".in", "r")){
  156.         freopen(task".in", "r", stdin);
  157.         freopen(task".out", "w", stdout);
  158.     }
  159.     typetest = 0;
  160. }
  161.  
  162. const int N = 1e3 + 2;
  163. int n, k;
  164. int a[N];
  165. queue<int> s;
  166. bool ck[2001];
  167. int trace[2001];
  168. int ans[2001];
  169.  
  170. inline void Enter(){
  171.     cin >> n >> k;
  172.     for(int i = 1; i <= n; ++i)
  173.         cin >> a[i], a[i] -= k;
  174. }
  175.  
  176. void traces(int i){
  177.     if(i - a[trace[i]] == 0){
  178.         ++ans[trace[i]];
  179.         return;
  180.     }
  181.     ++ans[trace[i]];
  182.     traces(i  - a[trace[i]]);
  183. }
  184.  
  185. inline void solve(){
  186.     for(int i = 1; i <= n; ++i)
  187.         if(a[i] > -1){
  188.             s.push(a[i]);
  189.             trace[a[i]] = i;
  190.             ck[a[i]] = 1;
  191.         }
  192.     bool ok = 0;
  193.     while(!s.empty()){
  194.         int c = s.front();
  195.         s.pop();
  196.         if(c == 0)
  197.             {ok = 1; break;}
  198.         for(int i = 1; i <= n; ++i)
  199.             if(c + a[i] <= 2000 && c + a[i] > -1 && !ck[c + a[i]]){
  200.                 s.push(c + a[i]);
  201.                 ck[c + a[i]] = 1;
  202.                 trace[c + a[i]] = i;
  203.             }
  204.     }
  205.     if(!ok) cout << "NO";
  206.     else{
  207.         cout << "YES\n";
  208.         traces(0);
  209.         for(int i = 1; i <= n; ++i)
  210.             cout << ans[i] << " ";
  211.     }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment