City Skyline — Zoning Laws, Construction Decrees & Audits

Company: inmobi_14june_iitbhu

Difficulty: hard

Problem Statement

City Skyline — Zoning Laws, Construction Decrees & Audits The city of Algorithms has a grand skyline of N skyscrapers standing in a row, numbered 1 to N from left to right. The i -th skyscraper is A[i] meters tall. Over the next year the Chief Architect issues Q events, in chronological order. Each event is one of three kinds. Type 1 — Zoning Law: 1 L R X No building in the range [L, R] may exceed height X . Every building in that range that is taller than X is demolished down to exactly X ; buildings already at height X or below are untouched. Formally A[i] = min(A[i], X) for every L <= i <= R . Type 2 — Construction Decree: 2 L R Y Crews add Y meters to every building in the range [L, R] . Formally A[i] = A[i] + Y for every L <= i <= R . Type 3 — Audit Query: 3 L R Report the total height of all buildings in the range [L, R] , that is A[L] + A[L+1] + ... + A[R] . Process the events in the order given and print the answer to every Type 3 event. Input Format The first l