void compit (int i = 1, int l = 0, int r = n - 1) { if (l == r) { t[i] += v[i]; t[i] -= (t[i] / k) * k; v[i] = 0; } else { int m = (l + r) / 2; v[i + i] += v[i]; v[i + i + 1] += v[i]; v[i] = 0; compit(i + i, l , m); compit(i + i + 1, m + 1, r); t[i] = t[i + i] + t[i + i + 1]; } }
int main() { freopen ("sum.in", "r", stdin); freopen ("sum.out", "w", stdout); int m; scanf ("%d%d%d", &n, &k, &m); for(i = 0; i < m; i++) { scanf ("%d%d%d", &cmd, &l, &r); l--, r--; if (cmd == 1) { update (l, r); } else { compit(); printf("%d\n", sum(l, r)); } } }
static int sacmp (stralloc const *a, stralloc const *b) { return compit(a->s, a->len - 1, b->s, b->len - 1) ; }
CompletionOrderEditor::CompletionOrderEditor(KPIM::LdapSearch *ldapSearch, QWidget *parent, const char *name) : KDialogBase(parent, name, true, i18n("Edit Completion Order"), Ok | Cancel, Ok, true), mConfig("kpimcompletionorder"), mDirty(false) { mItems.setAutoDelete(true); // The first step is to gather all the data, creating CompletionItem objects QValueList< LdapClient * > ldapClients = ldapSearch->clients(); for(QValueList<LdapClient *>::const_iterator it = ldapClients.begin(); it != ldapClients.end(); ++it) { //kdDebug(5300) << "LDAP: host " << (*it)->host() << " weight " << (*it)->completionWeight() << endl; mItems.append(new LDAPCompletionItem(*it)); } KABC::AddressBook *addressBook = KABC::StdAddressBook::self(true); QPtrList<KABC::Resource> resources = addressBook->resources(); for(QPtrListIterator<KABC::Resource> resit(resources); *resit; ++resit) { //kdDebug(5300) << "KABC Resource: " << (*resit)->className() << endl; ResourceABC *res = dynamic_cast<ResourceABC *>(*resit); if(res) // IMAP KABC resource { const QStringList subresources = res->subresources(); for(QStringList::const_iterator it = subresources.begin(); it != subresources.end(); ++it) { mItems.append(new KABCImapSubResCompletionItem(res, *it)); } } else // non-IMAP KABC resource { mItems.append(new SimpleCompletionItem(this, (*resit)->resourceName(), (*resit)->identifier())); } } #ifndef KDEPIM_NEW_DISTRLISTS // new distr lists are normal contact, so no separate item if using them // Add an item for distribution lists mItems.append(new SimpleCompletionItem(this, i18n("Distribution Lists"), "DistributionLists")); #endif // Now sort the items, then create the GUI mItems.sort(); QHBox *page = makeHBoxMainWidget(); mListView = new KListView(page); mListView->setSorting(-1); mListView->addColumn(QString::null); mListView->header()->hide(); for(QPtrListIterator<CompletionItem> compit(mItems); *compit; ++compit) { new CompletionViewItem(mListView, *compit); kdDebug(5300) << " " << (*compit)->label() << " " << (*compit)->completionWeight() << endl; } QVBox *upDownBox = new QVBox(page); mUpButton = new KPushButton(upDownBox, "mUpButton"); mUpButton->setIconSet(BarIconSet("up", KIcon::SizeSmall)); mUpButton->setEnabled(false); // b/c no item is selected yet mUpButton->setFocusPolicy(StrongFocus); mDownButton = new KPushButton(upDownBox, "mDownButton"); mDownButton->setIconSet(BarIconSet("down", KIcon::SizeSmall)); mDownButton->setEnabled(false); // b/c no item is selected yet mDownButton->setFocusPolicy(StrongFocus); QWidget *spacer = new QWidget(upDownBox); upDownBox->setStretchFactor(spacer, 100); connect(mListView, SIGNAL(selectionChanged(QListViewItem *)), SLOT(slotSelectionChanged(QListViewItem *))); connect(mUpButton, SIGNAL(clicked()), this, SLOT(slotMoveUp())); connect(mDownButton, SIGNAL(clicked()), this, SLOT(slotMoveDown())); }